@atlaskit/editor-plugin-table 7.9.0 → 7.10.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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/commands/column-resize.js +25 -7
- package/dist/cjs/nodeviews/TableComponent.js +11 -3
- package/dist/cjs/nodeviews/TableRow.js +1 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +4 -4
- package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +1 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +5 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +9 -7
- package/dist/cjs/transforms/column-width.js +3 -1
- package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
- package/dist/cjs/utils/index.js +12 -0
- package/dist/cjs/utils/nodes.js +6 -1
- package/dist/cjs/utils/table.js +34 -1
- package/dist/es2019/commands/column-resize.js +25 -7
- package/dist/es2019/nodeviews/TableComponent.js +12 -4
- package/dist/es2019/nodeviews/TableRow.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +4 -4
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +5 -3
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +9 -7
- package/dist/es2019/transforms/column-width.js +3 -1
- package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
- package/dist/es2019/utils/index.js +2 -2
- package/dist/es2019/utils/nodes.js +5 -0
- package/dist/es2019/utils/table.js +36 -1
- package/dist/esm/commands/column-resize.js +25 -7
- package/dist/esm/nodeviews/TableComponent.js +12 -4
- package/dist/esm/nodeviews/TableRow.js +1 -1
- package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +4 -4
- package/dist/esm/pm-plugins/table-resizing/utils/misc.js +1 -1
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +5 -3
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +9 -7
- package/dist/esm/transforms/column-width.js +3 -1
- package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
- package/dist/esm/utils/index.js +2 -2
- package/dist/esm/utils/nodes.js +5 -0
- package/dist/esm/utils/table.js +33 -0
- package/dist/types/commands/column-resize.d.ts +5 -4
- package/dist/types/nodeviews/TableComponent.d.ts +6 -54
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +2 -2
- package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +16 -20
- package/dist/types/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +32 -40
- package/dist/types/ui/TableFloatingControls/index.d.ts +16 -20
- package/dist/types/utils/index.d.ts +2 -2
- package/dist/types/utils/nodes.d.ts +1 -0
- package/dist/types/utils/table.d.ts +3 -0
- package/dist/types-ts4.5/commands/column-resize.d.ts +5 -4
- package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +6 -54
- package/dist/types-ts4.5/plugin.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +2 -2
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +16 -20
- package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +32 -40
- package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +16 -20
- package/dist/types-ts4.5/utils/index.d.ts +2 -2
- package/dist/types-ts4.5/utils/nodes.d.ts +1 -0
- package/dist/types-ts4.5/utils/table.d.ts +3 -0
- package/package.json +4 -1
- package/src/commands/column-resize.ts +42 -11
- package/src/nodeviews/TableComponent.tsx +21 -6
- package/src/nodeviews/TableRow.ts +2 -2
- package/src/plugin.tsx +1 -1
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +5 -5
- package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +7 -5
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +16 -10
- package/src/transforms/column-width.ts +10 -2
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +28 -11
- package/src/utils/index.ts +2 -1
- package/src/utils/nodes.ts +10 -0
- package/src/utils/table.ts +36 -0
|
@@ -8,6 +8,7 @@ import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
|
|
|
8
8
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
9
9
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
10
10
|
import type { Rect } from '@atlaskit/editor-tables/table-map';
|
|
11
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
11
12
|
|
|
12
13
|
import { getSelectedTableInfo } from '../../../utils';
|
|
13
14
|
|
|
@@ -34,7 +35,7 @@ export const getResizeState = ({
|
|
|
34
35
|
minWidth: number;
|
|
35
36
|
maxSize: number;
|
|
36
37
|
table: PMNode;
|
|
37
|
-
tableRef: HTMLTableElement;
|
|
38
|
+
tableRef: HTMLTableElement | null;
|
|
38
39
|
start: number;
|
|
39
40
|
domAtPos: (pos: number) => { node: Node; offset: number };
|
|
40
41
|
isTableScalingEnabled: boolean;
|
|
@@ -107,12 +108,12 @@ export const getResizeState = ({
|
|
|
107
108
|
// updates Colgroup DOM node with new widths
|
|
108
109
|
export const updateColgroup = (
|
|
109
110
|
state: ResizeState,
|
|
110
|
-
tableRef: HTMLElement,
|
|
111
|
+
tableRef: HTMLElement | null,
|
|
111
112
|
tableNode?: PMNode,
|
|
112
113
|
isTableScalingEnabled?: boolean,
|
|
113
114
|
): void => {
|
|
114
|
-
const cols = tableRef
|
|
115
|
-
const columnsCount = cols
|
|
115
|
+
const cols = tableRef?.querySelectorAll('col');
|
|
116
|
+
const columnsCount = cols?.length;
|
|
116
117
|
/**
|
|
117
118
|
updateColgroup will update whole table scale when click the column resize handle, this behavior will affect when table overflowed, when now resize handle been dragged and extend to make table overflowed, table will show overflow. This need to be confirmed because it conflict with how isTableScalingEnabled work.
|
|
118
119
|
We don't want to scale the table when resizing columns, only when viewpoint shrinks the table.
|
|
@@ -123,11 +124,11 @@ export const updateColgroup = (
|
|
|
123
124
|
state.cols
|
|
124
125
|
.filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
125
126
|
.forEach((column, i) => {
|
|
126
|
-
const fixedColWidth = getColWidthFix(column.width, columnsCount);
|
|
127
|
+
const fixedColWidth = getColWidthFix(column.width, columnsCount ?? 0);
|
|
127
128
|
const scaledWidth = fixedColWidth * scalePercent;
|
|
128
129
|
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
129
130
|
// we aren't handling the remaining pixels here when the 48px min width is reached
|
|
130
|
-
if (cols[i]) {
|
|
131
|
+
if (cols?.[i]) {
|
|
131
132
|
cols[i].style.width = `${finalWidth}px`;
|
|
132
133
|
}
|
|
133
134
|
});
|
|
@@ -135,10 +136,10 @@ export const updateColgroup = (
|
|
|
135
136
|
state.cols
|
|
136
137
|
.filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
|
|
137
138
|
.forEach((column, i) => {
|
|
138
|
-
if (cols[i]) {
|
|
139
|
+
if (cols?.[i]) {
|
|
139
140
|
cols[i].style.width = `${getColWidthFix(
|
|
140
141
|
column.width,
|
|
141
|
-
columnsCount,
|
|
142
|
+
columnsCount ?? 0,
|
|
142
143
|
)}px`;
|
|
143
144
|
}
|
|
144
145
|
});
|
|
@@ -361,8 +362,13 @@ export const getNewResizeStateFromSelectedColumns = (
|
|
|
361
362
|
return;
|
|
362
363
|
}
|
|
363
364
|
|
|
364
|
-
const maybeTable = domAtPos(table.start).node
|
|
365
|
-
|
|
365
|
+
const maybeTable = domAtPos(table.start).node;
|
|
366
|
+
|
|
367
|
+
const maybeTableElement =
|
|
368
|
+
maybeTable instanceof HTMLElement ? maybeTable : null;
|
|
369
|
+
const tableRef = getBooleanFF('platform.editor.explicit-html-element-check')
|
|
370
|
+
? maybeTableElement?.closest('table')
|
|
371
|
+
: (maybeTable as HTMLElement)?.closest('table');
|
|
366
372
|
|
|
367
373
|
if (!tableRef) {
|
|
368
374
|
return;
|
|
@@ -6,6 +6,7 @@ import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
|
|
|
6
6
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
7
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
8
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
9
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
9
10
|
|
|
10
11
|
import type { ResizeState } from '../pm-plugins/table-resizing/utils';
|
|
11
12
|
import {
|
|
@@ -119,8 +120,15 @@ export const rescaleColumns =
|
|
|
119
120
|
|
|
120
121
|
const newTable = tr.doc.nodeAt(table.pos);
|
|
121
122
|
const domAtPos = view.domAtPos.bind(view);
|
|
122
|
-
const maybeTable = domAtPos(table.start).node
|
|
123
|
-
const
|
|
123
|
+
const maybeTable = domAtPos(table.start).node;
|
|
124
|
+
const maybeTableElement = getBooleanFF(
|
|
125
|
+
'platform.editor.explicit-html-element-check',
|
|
126
|
+
)
|
|
127
|
+
? maybeTable instanceof HTMLElement
|
|
128
|
+
? maybeTable
|
|
129
|
+
: null
|
|
130
|
+
: (maybeTable as HTMLElement | null);
|
|
131
|
+
const tableRef = maybeTableElement?.closest('table');
|
|
124
132
|
|
|
125
133
|
if (!tableRef || !newTable) {
|
|
126
134
|
return tr;
|
|
@@ -16,6 +16,7 @@ import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
|
16
16
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
17
17
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
18
18
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
19
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
19
20
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
20
21
|
import { token } from '@atlaskit/tokens';
|
|
21
22
|
|
|
@@ -142,19 +143,35 @@ const DragControlsComponent = ({
|
|
|
142
143
|
|
|
143
144
|
const handleMouseMove = useCallback(
|
|
144
145
|
(e: MouseEvent) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
if (getBooleanFF('platform.editor.explicit-html-element-check')) {
|
|
147
|
+
const target =
|
|
148
|
+
e.nativeEvent.target instanceof Element ? e.nativeEvent.target : null;
|
|
149
|
+
const isParentDragControls = target?.closest(
|
|
150
|
+
`.${ClassName.DRAG_ROW_CONTROLS}`,
|
|
151
|
+
);
|
|
152
|
+
const rowIndex = target?.getAttribute('data-start-index');
|
|
151
153
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
// avoid updating if event target is not related
|
|
155
|
+
if (!isParentDragControls || !rowIndex) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
156
158
|
|
|
157
|
-
|
|
159
|
+
updateCellHoverLocation(Number(rowIndex));
|
|
160
|
+
} else {
|
|
161
|
+
const isParentDragControls = (e.nativeEvent.target as Element).closest(
|
|
162
|
+
`.${ClassName.DRAG_ROW_CONTROLS}`,
|
|
163
|
+
);
|
|
164
|
+
const rowIndex = (e.nativeEvent.target as Element).getAttribute(
|
|
165
|
+
'data-start-index',
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
// avoid updating if event target is not related
|
|
169
|
+
if (!isParentDragControls || !rowIndex) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
updateCellHoverLocation(Number(rowIndex));
|
|
174
|
+
}
|
|
158
175
|
},
|
|
159
176
|
[updateCellHoverLocation],
|
|
160
177
|
);
|
package/src/utils/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ export {
|
|
|
26
26
|
getTableWidth,
|
|
27
27
|
tablesHaveDifferentColumnWidths,
|
|
28
28
|
tablesHaveDifferentNoOfColumns,
|
|
29
|
+
tablesHaveDifferentNoOfRows,
|
|
29
30
|
isTableNested,
|
|
30
31
|
anyChildCellMergedAcrossRow,
|
|
31
32
|
supportedHeaderRow,
|
|
@@ -75,7 +76,7 @@ export {
|
|
|
75
76
|
} from './row-controls';
|
|
76
77
|
export type { RowParams } from './row-controls';
|
|
77
78
|
export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
|
|
78
|
-
export { getMergedCellsPositions } from './table';
|
|
79
|
+
export { getMergedCellsPositions, getAssistiveMessage } from './table';
|
|
79
80
|
export { updatePluginStateDecorations } from './update-plugin-state-decorations';
|
|
80
81
|
export {
|
|
81
82
|
hasMergedCellsInColumn,
|
package/src/utils/nodes.ts
CHANGED
|
@@ -94,6 +94,16 @@ export const tablesHaveDifferentNoOfColumns = (
|
|
|
94
94
|
return prevMap.width !== currentMap.width;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
export const tablesHaveDifferentNoOfRows = (
|
|
98
|
+
currentTable: PmNode,
|
|
99
|
+
previousTable: PmNode,
|
|
100
|
+
): boolean => {
|
|
101
|
+
const prevMap = TableMap.get(previousTable);
|
|
102
|
+
const currentMap = TableMap.get(currentTable);
|
|
103
|
+
|
|
104
|
+
return prevMap.height !== currentMap.height;
|
|
105
|
+
};
|
|
106
|
+
|
|
97
107
|
function filterNearSelection<T, U>(
|
|
98
108
|
selection: Selection,
|
|
99
109
|
findNode: (selection: Selection) => { pos: number; node: PmNode } | undefined,
|
package/src/utils/table.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { IntlShape } from 'react-intl-next';
|
|
2
|
+
|
|
3
|
+
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
4
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
1
5
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
6
|
import type { Rect } from '@atlaskit/editor-tables/table-map';
|
|
3
7
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
@@ -30,3 +34,35 @@ export const colsToRect = (cols: Array<number>, noOfRows: number): Rect => ({
|
|
|
30
34
|
top: 0,
|
|
31
35
|
bottom: noOfRows,
|
|
32
36
|
});
|
|
37
|
+
|
|
38
|
+
export const getAssistiveMessage = (
|
|
39
|
+
prevTableNode: PmNode,
|
|
40
|
+
currentTableNode: PmNode,
|
|
41
|
+
intl: IntlShape,
|
|
42
|
+
) => {
|
|
43
|
+
const { formatMessage } = intl;
|
|
44
|
+
const prevTableMap = TableMap.get(prevTableNode);
|
|
45
|
+
const currentTableMap = TableMap.get(currentTableNode);
|
|
46
|
+
|
|
47
|
+
if (currentTableMap.width !== prevTableMap.width) {
|
|
48
|
+
const diff = Math.abs(currentTableMap.width - prevTableMap.width);
|
|
49
|
+
if (currentTableMap.width > prevTableMap.width) {
|
|
50
|
+
return formatMessage(messages.columnsAreInserted, { count: diff });
|
|
51
|
+
}
|
|
52
|
+
if (currentTableMap.width < prevTableMap.width) {
|
|
53
|
+
return formatMessage(messages.columnsAreRemoved, { count: diff });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (currentTableMap.height !== prevTableMap.height) {
|
|
58
|
+
const diff = Math.abs(currentTableMap.height - prevTableMap.height);
|
|
59
|
+
if (currentTableMap.height > prevTableMap.height) {
|
|
60
|
+
return formatMessage(messages.rowsAreInserted, { count: diff });
|
|
61
|
+
}
|
|
62
|
+
if (currentTableMap.height < prevTableMap.height) {
|
|
63
|
+
return formatMessage(messages.rowsAreRemoved, { count: diff });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return '';
|
|
68
|
+
};
|