@atlaskit/editor-plugin-table 0.0.6 → 0.0.8
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 +17 -0
- package/dist/cjs/plugins/table/event-handlers.js +7 -6
- package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
- package/dist/cjs/plugins/table/nodeviews/tableCell.js +4 -4
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/cjs/plugins/table/toolbar.js +0 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/index.js +23 -10
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +23 -10
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -4
- package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/event-handlers.js +8 -7
- package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
- package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -4
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/es2019/plugins/table/toolbar.js +1 -2
- package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/index.js +18 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +18 -3
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +2 -2
- package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/event-handlers.js +8 -7
- package/dist/esm/plugins/table/nodeviews/table.js +4 -2
- package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -4
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
- package/dist/esm/plugins/table/toolbar.js +1 -2
- package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/index.js +19 -9
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +19 -9
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +2 -2
- package/dist/esm/plugins/table/utils/column-controls.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +5 -8
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +5 -5
- package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +1 -0
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +5 -8
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +5 -5
- package/package.json +10 -3
- package/src/__tests__/unit/analytics.ts +737 -0
- package/src/__tests__/unit/collab.ts +76 -0
- package/src/__tests__/unit/commands/sort.ts +230 -0
- package/src/__tests__/unit/copy-paste.ts +686 -0
- package/src/__tests__/unit/event-handlers/index.ts +106 -0
- package/src/__tests__/unit/event-handlers.ts +202 -0
- package/src/__tests__/unit/fix-tables.ts +156 -0
- package/src/__tests__/unit/floating-toolbar.ts +95 -0
- package/src/__tests__/unit/handlers.ts +81 -0
- package/src/__tests__/unit/hover-selection.ts +277 -0
- package/src/__tests__/unit/index-with-fake-timers.ts +107 -0
- package/src/__tests__/unit/index.ts +986 -0
- package/src/__tests__/unit/keymap.ts +602 -0
- package/src/__tests__/unit/layout.ts +196 -0
- package/src/__tests__/unit/nodeviews/cell.ts +167 -0
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +33 -0
- package/src/__tests__/unit/sort-column.ts +512 -0
- package/src/__tests__/unit/transforms/delete-columns.ts +499 -0
- package/src/__tests__/unit/transforms/delete-rows.ts +557 -0
- package/src/__tests__/unit/transforms/merging.ts +374 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +80 -0
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +95 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +175 -0
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +266 -0
- package/src/__tests__/unit/ui/RowControls.tsx +301 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +93 -0
- package/src/__tests__/unit/undo-redo.ts +202 -0
- package/src/__tests__/unit/utils/dom.ts +286 -0
- package/src/__tests__/unit/utils/nodes.ts +59 -0
- package/src/__tests__/unit/utils/row-controls.ts +176 -0
- package/src/__tests__/unit/utils/table.ts +93 -0
- package/src/__tests__/unit/utils.ts +652 -0
- package/src/plugins/table/__tests__/unit/commands/insert.ts +2 -2
- package/src/plugins/table/__tests__/unit/commands.ts +2 -2
- package/src/plugins/table/__tests__/unit/nodeviews/TableComponent.tsx +2 -2
- package/src/plugins/table/__tests__/unit/nodeviews/table.ts +1 -0
- package/src/plugins/table/event-handlers.ts +5 -6
- package/src/plugins/table/nodeviews/table.tsx +7 -0
- package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
- package/src/plugins/table/nodeviews/types.ts +1 -0
- package/src/plugins/table/pm-plugins/table-resizing/utils/column-state.ts +1 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +6 -2
- package/src/plugins/table/toolbar.ts +0 -1
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +1 -1
- package/src/plugins/table/ui/TableFloatingControls/CornerControls/index.tsx +19 -1
- package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +16 -1
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +2 -2
- package/src/plugins/table/utils/column-controls.ts +1 -1
|
@@ -73,6 +73,7 @@ describe('table -> nodeviews -> table.tsx', () => {
|
|
|
73
73
|
tableRenderOptimization: true,
|
|
74
74
|
getEditorContainerWidth: () => ({ width: 500 }),
|
|
75
75
|
getEditorFeatureFlags: () => ({}),
|
|
76
|
+
hasIntlContext: true,
|
|
76
77
|
}).init();
|
|
77
78
|
|
|
78
79
|
renderSpy = jest.spyOn(tableNodeView, 'render');
|
|
@@ -18,11 +18,6 @@ import { EditorView } from 'prosemirror-view';
|
|
|
18
18
|
|
|
19
19
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
20
20
|
|
|
21
|
-
// import {
|
|
22
|
-
// isElementInTableCell,
|
|
23
|
-
// isLastItemMediaGroup,
|
|
24
|
-
// setNodeSelection,
|
|
25
|
-
// } from '@atlaskit/editor-core/src/utils';
|
|
26
21
|
import {
|
|
27
22
|
isElementInTableCell,
|
|
28
23
|
isLastItemMediaGroup,
|
|
@@ -160,8 +155,12 @@ export const handleClick = (view: EditorView, event: Event): boolean => {
|
|
|
160
155
|
},
|
|
161
156
|
},
|
|
162
157
|
} = view;
|
|
163
|
-
const
|
|
158
|
+
const cellPos = map.map[cellIndex];
|
|
159
|
+
if (isNaN(cellPos) || cellPos === undefined || typeof cellPos !== 'number') {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
164
162
|
|
|
163
|
+
const editorElement = table.node.nodeAt(cellPos) as PmNode;
|
|
165
164
|
/** Only if the last item is media group, insert a paragraph */
|
|
166
165
|
if (isLastItemMediaGroup(editorElement)) {
|
|
167
166
|
const posInTable = map.map[cellIndex] + editorElement.nodeSize;
|
|
@@ -72,6 +72,10 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
72
72
|
props.portalProviderAPI,
|
|
73
73
|
props.eventDispatcher,
|
|
74
74
|
props,
|
|
75
|
+
undefined,
|
|
76
|
+
undefined,
|
|
77
|
+
undefined,
|
|
78
|
+
props.hasIntlContext,
|
|
75
79
|
);
|
|
76
80
|
this.getPos = props.getPos;
|
|
77
81
|
this.tableRenderOptimization = props.tableRenderOptimization;
|
|
@@ -233,6 +237,8 @@ export const createTableView = (
|
|
|
233
237
|
const { pluginConfig } = getPluginState(view.state);
|
|
234
238
|
const { allowColumnResizing } = getPluginConfig(pluginConfig);
|
|
235
239
|
const { tableRenderOptimization } = getEditorFeatureFlags();
|
|
240
|
+
const hasIntlContext = true;
|
|
241
|
+
|
|
236
242
|
return new TableView({
|
|
237
243
|
node,
|
|
238
244
|
view,
|
|
@@ -244,5 +250,6 @@ export const createTableView = (
|
|
|
244
250
|
tableRenderOptimization,
|
|
245
251
|
getEditorContainerWidth,
|
|
246
252
|
getEditorFeatureFlags,
|
|
253
|
+
hasIntlContext,
|
|
247
254
|
}).init();
|
|
248
255
|
};
|
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
} from '@atlaskit/adf-schema';
|
|
12
12
|
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
13
13
|
|
|
14
|
+
const DEFAULT_COL_SPAN = 1;
|
|
15
|
+
const DEFAULT_ROW_SPAN = 1;
|
|
16
|
+
|
|
14
17
|
export default class TableCellNodeView implements NodeView {
|
|
15
18
|
node: Node;
|
|
16
19
|
dom: HTMLElement;
|
|
@@ -62,11 +65,9 @@ export default class TableCellNodeView implements NodeView {
|
|
|
62
65
|
|
|
63
66
|
// need to rerender when colspan/rowspan in dom are different from the node attrs
|
|
64
67
|
// this can happen when undoing merge cells
|
|
65
|
-
const defaultColspan = 1,
|
|
66
|
-
defaultRowspan = 1;
|
|
67
68
|
if (
|
|
68
|
-
colspan !== (node.attrs.colspan ||
|
|
69
|
-
rowspan !== (node.attrs.rowspan ||
|
|
69
|
+
colspan !== (node.attrs.colspan || DEFAULT_COL_SPAN) ||
|
|
70
|
+
rowspan !== (node.attrs.rowspan || DEFAULT_ROW_SPAN)
|
|
70
71
|
) {
|
|
71
72
|
return false;
|
|
72
73
|
}
|
|
@@ -62,7 +62,7 @@ export const getCellsRefsInColumn = (
|
|
|
62
62
|
return cells;
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
// calculates column
|
|
65
|
+
// calculates column widths based on `cells` DOM refs
|
|
66
66
|
export const calculateColumnWidth = (
|
|
67
67
|
cells: HTMLElement[],
|
|
68
68
|
calculateColumnWidthCb: (
|
|
@@ -8,8 +8,8 @@ export const growColumn = (
|
|
|
8
8
|
amount: number,
|
|
9
9
|
selectedColumns?: number[],
|
|
10
10
|
): ResizeState => {
|
|
11
|
-
// can't grow the last column
|
|
12
|
-
if (!state.cols[colIndex + 1]) {
|
|
11
|
+
// can't grow if columns don't exist or it's the last column
|
|
12
|
+
if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
|
|
13
13
|
return state;
|
|
14
14
|
}
|
|
15
15
|
const res = moveSpaceFrom(state, colIndex + 1, colIndex, amount);
|
|
@@ -32,6 +32,10 @@ export const shrinkColumn = (
|
|
|
32
32
|
amount: number,
|
|
33
33
|
selectedColumns?: number[],
|
|
34
34
|
): ResizeState => {
|
|
35
|
+
// can't shrink if columns don't exist
|
|
36
|
+
if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
35
39
|
// try to shrink dragging column by giving from the column to the right first
|
|
36
40
|
const res = moveSpaceFrom(state, colIndex, colIndex + 1, -amount);
|
|
37
41
|
let newState = res.state;
|
|
@@ -57,7 +57,6 @@ import { findParentDomRefOfType } from 'prosemirror-utils';
|
|
|
57
57
|
import { EditorView } from 'prosemirror-view';
|
|
58
58
|
import { closestElement } from '@atlaskit/editor-common/utils';
|
|
59
59
|
|
|
60
|
-
// TODO: ED-14403 investigate why these translations don't work
|
|
61
60
|
export const messages = defineMessages({
|
|
62
61
|
tableOptions: {
|
|
63
62
|
id: 'fabric.editor.tableOptions',
|
|
@@ -37,7 +37,7 @@ it.skip('TODO: restore unit', () => {});
|
|
|
37
37
|
// }));
|
|
38
38
|
// });
|
|
39
39
|
|
|
40
|
-
//
|
|
40
|
+
// it('should render contextual menu when no tableCellPosition is passed but exist on editor state ', () => {
|
|
41
41
|
// const intl = createIntl({ locale: 'en' });
|
|
42
42
|
// const wrapper = shallow(
|
|
43
43
|
// <ContextualMenu
|
|
@@ -34,7 +34,7 @@ it.skip('TODO: restore unit', () => {});
|
|
|
34
34
|
// }));
|
|
35
35
|
// });
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// it('should render floating contextual menu when no tableCellPosition is passed but exist on editor state ', () => {
|
|
38
38
|
// const wrapper = shallow(
|
|
39
39
|
// <FloatingContextualMenu
|
|
40
40
|
// editorView={editorView}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
2
4
|
|
|
3
5
|
import classnames from 'classnames';
|
|
4
6
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
@@ -12,6 +14,15 @@ import { EditorView } from 'prosemirror-view';
|
|
|
12
14
|
import { clearHoverSelection, hoverTable } from '../../../commands';
|
|
13
15
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
14
16
|
|
|
17
|
+
const messages = defineMessages({
|
|
18
|
+
cornerControl: {
|
|
19
|
+
id: 'fabric.editor.cornerControl',
|
|
20
|
+
defaultMessage: 'Highlight table',
|
|
21
|
+
description:
|
|
22
|
+
'A button on the upper left corner of the table that shows up when the table is in focus. Clicking on it will select the entire table.',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
15
26
|
export interface Props {
|
|
16
27
|
editorView: EditorView;
|
|
17
28
|
tableRef?: HTMLTableElement;
|
|
@@ -23,13 +34,17 @@ export interface Props {
|
|
|
23
34
|
stickyTop?: number;
|
|
24
35
|
}
|
|
25
36
|
|
|
26
|
-
|
|
37
|
+
class CornerControlComponent extends Component<
|
|
38
|
+
Props & WrappedComponentProps,
|
|
39
|
+
any
|
|
40
|
+
> {
|
|
27
41
|
render() {
|
|
28
42
|
const {
|
|
29
43
|
isInDanger,
|
|
30
44
|
tableRef,
|
|
31
45
|
isHeaderColumnEnabled,
|
|
32
46
|
isHeaderRowEnabled,
|
|
47
|
+
intl: { formatMessage },
|
|
33
48
|
} = this.props;
|
|
34
49
|
if (!tableRef) {
|
|
35
50
|
return null;
|
|
@@ -50,6 +65,7 @@ export default class CornerControls extends Component<Props, any> {
|
|
|
50
65
|
}}
|
|
51
66
|
>
|
|
52
67
|
<button
|
|
68
|
+
aria-label={formatMessage(messages.cornerControl)}
|
|
53
69
|
type="button"
|
|
54
70
|
className={classnames(ClassName.CONTROLS_CORNER_BUTTON, {
|
|
55
71
|
danger: isActive && isInDanger,
|
|
@@ -103,3 +119,5 @@ export default class CornerControls extends Component<Props, any> {
|
|
|
103
119
|
hoverTable()(state, dispatch);
|
|
104
120
|
};
|
|
105
121
|
}
|
|
122
|
+
|
|
123
|
+
export const CornerControls = injectIntl(CornerControlComponent);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
2
|
|
|
3
3
|
import { EditorView } from 'prosemirror-view';
|
|
4
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
5
|
+
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
4
6
|
|
|
5
7
|
import { clearHoverSelection } from '../../../commands';
|
|
6
8
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
@@ -12,6 +14,15 @@ import {
|
|
|
12
14
|
} from '../../../utils';
|
|
13
15
|
import { tableControlsSpacing, tableToolbarSize } from '../../consts';
|
|
14
16
|
|
|
17
|
+
const messages = defineMessages({
|
|
18
|
+
rowControl: {
|
|
19
|
+
id: 'fabric.editor.rowControl',
|
|
20
|
+
defaultMessage: 'Highlight row',
|
|
21
|
+
description:
|
|
22
|
+
'A button on the left of each row that shows up when the table is in focus. Clicking on it will select the entire row.',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
15
26
|
export interface Props {
|
|
16
27
|
editorView: EditorView;
|
|
17
28
|
tableRef: HTMLTableElement;
|
|
@@ -24,7 +35,7 @@ export interface Props {
|
|
|
24
35
|
stickyTop?: number;
|
|
25
36
|
}
|
|
26
37
|
|
|
27
|
-
|
|
38
|
+
class RowControlsComponent extends Component<Props & WrappedComponentProps> {
|
|
28
39
|
render() {
|
|
29
40
|
const {
|
|
30
41
|
editorView,
|
|
@@ -32,6 +43,7 @@ export default class RowControls extends Component<Props> {
|
|
|
32
43
|
hoveredRows,
|
|
33
44
|
isInDanger,
|
|
34
45
|
isResizing,
|
|
46
|
+
intl: { formatMessage },
|
|
35
47
|
} = this.props;
|
|
36
48
|
if (!tableRef) {
|
|
37
49
|
return null;
|
|
@@ -89,6 +101,7 @@ export default class RowControls extends Component<Props> {
|
|
|
89
101
|
}}
|
|
90
102
|
>
|
|
91
103
|
<button
|
|
104
|
+
aria-label={formatMessage(messages.rowControl)}
|
|
92
105
|
type="button"
|
|
93
106
|
className={`${ClassName.ROW_CONTROLS_BUTTON}
|
|
94
107
|
${ClassName.CONTROLS_BUTTON}
|
|
@@ -117,3 +130,5 @@ export default class RowControls extends Component<Props> {
|
|
|
117
130
|
clearHoverSelection()(state, dispatch);
|
|
118
131
|
};
|
|
119
132
|
}
|
|
133
|
+
|
|
134
|
+
export const RowControls = injectIntl(RowControlsComponent);
|
|
@@ -11,9 +11,9 @@ import { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
|
11
11
|
|
|
12
12
|
import { isSelectionUpdated } from '../../utils';
|
|
13
13
|
|
|
14
|
-
import CornerControls from './CornerControls';
|
|
14
|
+
import { CornerControls } from './CornerControls';
|
|
15
15
|
import NumberColumn from './NumberColumn';
|
|
16
|
-
import RowControls from './RowControls';
|
|
16
|
+
import { RowControls } from './RowControls';
|
|
17
17
|
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
18
18
|
|
|
19
19
|
export interface Props {
|
|
@@ -144,7 +144,7 @@ const getRelativeDomCellWidths = ({
|
|
|
144
144
|
// for cells in a table with unchanged column widths,
|
|
145
145
|
// these are identified by the lack of colwidth data attribute,
|
|
146
146
|
// return equally partitioned total cell width in DOM for each cell.
|
|
147
|
-
if (colspan
|
|
147
|
+
if (colspan === 1 || !colwidth) {
|
|
148
148
|
return new Array(colspan).fill(width / colspan);
|
|
149
149
|
}
|
|
150
150
|
|