@atlaskit/editor-plugin-table 2.10.7 → 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.
- package/CHANGELOG.md +41 -0
- package/dist/cjs/plugins/table/commands/misc.js +58 -5
- package/dist/cjs/plugins/table/event-handlers.js +3 -6
- package/dist/cjs/plugins/table/index.js +66 -63
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +5 -5
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +13 -19
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-resizing.js +18 -5
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/index.js +6 -0
- package/dist/cjs/plugins/table/pm-plugins/main.js +7 -3
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -0
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +2 -0
- package/dist/cjs/plugins/table/reducer.js +26 -2
- package/dist/cjs/plugins/table/types.js +1 -0
- package/dist/cjs/plugins/table/ui/ColumnResizeWidget/index.js +44 -0
- package/dist/cjs/plugins/table/ui/messages.js +5 -0
- package/dist/cjs/plugins/table/utils/decoration.js +17 -4
- package/dist/es2019/plugins/table/commands/misc.js +49 -5
- package/dist/es2019/plugins/table/event-handlers.js +3 -6
- package/dist/es2019/plugins/table/index.js +14 -10
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +5 -5
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +14 -17
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-resizing.js +12 -2
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/index.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/main.js +6 -3
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -0
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +2 -0
- package/dist/es2019/plugins/table/reducer.js +29 -2
- package/dist/es2019/plugins/table/types.js +1 -0
- package/dist/es2019/plugins/table/ui/ColumnResizeWidget/index.js +35 -0
- package/dist/es2019/plugins/table/ui/messages.js +5 -0
- package/dist/es2019/plugins/table/utils/decoration.js +16 -5
- package/dist/esm/plugins/table/commands/misc.js +56 -5
- package/dist/esm/plugins/table/event-handlers.js +3 -6
- package/dist/esm/plugins/table/index.js +66 -63
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +5 -5
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +13 -19
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-resizing.js +15 -3
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/index.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/main.js +8 -4
- package/dist/esm/plugins/table/pm-plugins/table-resizing/event-handlers.js +5 -0
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +2 -0
- package/dist/esm/plugins/table/reducer.js +26 -2
- package/dist/esm/plugins/table/types.js +1 -0
- package/dist/esm/plugins/table/ui/ColumnResizeWidget/index.js +35 -0
- package/dist/esm/plugins/table/ui/messages.js +5 -0
- package/dist/esm/plugins/table/utils/decoration.js +17 -4
- package/dist/types/plugins/table/commands/misc.d.ts +8 -6
- package/dist/types/plugins/table/event-handlers.d.ts +3 -3
- package/dist/types/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +4 -2
- package/dist/types/plugins/table/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/main.d.ts +2 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/plugin.d.ts +2 -2
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -3
- package/dist/types/plugins/table/reducer.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +18 -0
- package/dist/types/plugins/table/ui/ColumnResizeWidget/index.d.ts +9 -0
- package/dist/types/plugins/table/ui/messages.d.ts +5 -0
- package/dist/types/plugins/table/utils/decoration.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +8 -6
- package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +3 -3
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +4 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/plugin.d.ts +2 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -3
- package/dist/types-ts4.5/plugins/table/reducer.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +18 -0
- package/dist/types-ts4.5/plugins/table/ui/ColumnResizeWidget/index.d.ts +9 -0
- package/dist/types-ts4.5/plugins/table/ui/messages.d.ts +5 -0
- package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -1
- package/package.json +4 -4
- package/src/__tests__/unit/event-handlers.ts +1 -1
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +6 -8
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +22 -15
- package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +2 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +9 -10
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +9 -9
- package/src/plugins/table/commands/misc.ts +84 -7
- package/src/plugins/table/event-handlers.ts +11 -16
- package/src/plugins/table/index.tsx +6 -4
- package/src/plugins/table/nodeviews/TableContainer.tsx +4 -4
- package/src/plugins/table/nodeviews/TableResizer.tsx +12 -20
- package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +34 -7
- package/src/plugins/table/pm-plugins/decorations/utils/index.ts +4 -1
- package/src/plugins/table/pm-plugins/main.ts +7 -1
- package/src/plugins/table/pm-plugins/table-resizing/event-handlers.ts +5 -0
- package/src/plugins/table/pm-plugins/table-resizing/plugin.ts +3 -5
- package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +5 -3
- package/src/plugins/table/reducer.ts +51 -3
- package/src/plugins/table/types.ts +19 -0
- package/src/plugins/table/ui/ColumnResizeWidget/index.tsx +53 -0
- package/src/plugins/table/ui/messages.ts +5 -0
- package/src/plugins/table/utils/decoration.ts +27 -5
- package/tmp/api-report-tmp.d.ts +111 -0
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { fireEvent, render } from '@testing-library/react';
|
|
4
4
|
|
|
5
|
-
import { TableAttributes } from '@atlaskit/adf-schema';
|
|
5
|
+
import type { TableAttributes } from '@atlaskit/adf-schema';
|
|
6
6
|
import {
|
|
7
7
|
ACTION_SUBJECT,
|
|
8
8
|
EVENT_TYPE,
|
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
import { akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
12
12
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
13
13
|
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
14
|
+
import type { DocBuilder } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
14
15
|
import {
|
|
15
16
|
doc,
|
|
16
|
-
DocBuilder,
|
|
17
17
|
p,
|
|
18
18
|
table,
|
|
19
19
|
td,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
TableContainer,
|
|
28
28
|
} from '../../../plugins/table/nodeviews/TableContainer';
|
|
29
29
|
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
30
|
-
import { TablePluginState } from '../../../plugins/table/types';
|
|
30
|
+
import type { TablePluginState } from '../../../plugins/table/types';
|
|
31
31
|
|
|
32
32
|
const mockStartMeasure = jest.fn();
|
|
33
33
|
const mockEndMeasure = jest.fn(() => {
|
|
@@ -46,6 +46,15 @@ jest.mock('../../../plugins/table/utils/analytics', () => ({
|
|
|
46
46
|
},
|
|
47
47
|
}));
|
|
48
48
|
|
|
49
|
+
jest.mock('react-intl-next', () => {
|
|
50
|
+
return {
|
|
51
|
+
...(jest.requireActual('react-intl-next') as any),
|
|
52
|
+
useIntl: jest.fn().mockReturnValue({
|
|
53
|
+
formatMessage: (descriptor: any) => descriptor.defaultMessage,
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
49
58
|
describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
50
59
|
const createEditor = createEditorFactory<TablePluginState>();
|
|
51
60
|
const editor = (
|
|
@@ -57,7 +66,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
57
66
|
editorProps: {
|
|
58
67
|
allowTables: false,
|
|
59
68
|
dangerouslyAppendPlugins: {
|
|
60
|
-
__plugins: [tablePlugin()],
|
|
69
|
+
__plugins: [tablePlugin({ config: undefined })],
|
|
61
70
|
},
|
|
62
71
|
featureFlags,
|
|
63
72
|
},
|
|
@@ -199,9 +208,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
199
208
|
}
|
|
200
209
|
pluginInjectionApi={
|
|
201
210
|
{
|
|
202
|
-
|
|
203
|
-
analytics: { actions: { attachAnalyticsEvent: analyticsMock } },
|
|
204
|
-
},
|
|
211
|
+
analytics: { actions: { attachAnalyticsEvent: analyticsMock } },
|
|
205
212
|
} as any
|
|
206
213
|
}
|
|
207
214
|
/>,
|
|
@@ -213,11 +220,11 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
213
220
|
test('fires when resizing is finished', async () => {
|
|
214
221
|
const { container, analyticsMock } = buildContainer({ layout: 'wide' });
|
|
215
222
|
|
|
216
|
-
fireEvent.mouseDown(container.querySelector('.resizer-handle
|
|
217
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle
|
|
218
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle
|
|
219
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle
|
|
220
|
-
fireEvent.mouseUp(container.querySelector('.resizer-handle
|
|
223
|
+
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
224
|
+
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
225
|
+
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
226
|
+
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!);
|
|
227
|
+
fireEvent.mouseUp(container.querySelector('.resizer-handle.right')!);
|
|
221
228
|
|
|
222
229
|
expect(analyticsMock).toHaveBeenCalledWith({
|
|
223
230
|
action: TABLE_ACTION.RESIZED,
|
|
@@ -263,11 +270,11 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
263
270
|
test('calls useMeasureFramerate handlers', async () => {
|
|
264
271
|
const { container } = buildContainer({ layout: 'wide' });
|
|
265
272
|
|
|
266
|
-
fireEvent.mouseDown(container.querySelector('.resizer-handle
|
|
267
|
-
fireEvent.mouseMove(container.querySelector('.resizer-handle
|
|
273
|
+
fireEvent.mouseDown(container.querySelector('.resizer-handle.right')!);
|
|
274
|
+
fireEvent.mouseMove(container.querySelector('.resizer-handle.right')!, {
|
|
268
275
|
clientX: 100,
|
|
269
276
|
});
|
|
270
|
-
fireEvent.mouseUp(container.querySelector('.resizer-handle
|
|
277
|
+
fireEvent.mouseUp(container.querySelector('.resizer-handle.right')!);
|
|
271
278
|
|
|
272
279
|
expect(mockStartMeasure).toHaveBeenCalled();
|
|
273
280
|
expect(mockEndMeasure).toHaveBeenCalled();
|
|
@@ -3,12 +3,12 @@ import React from 'react';
|
|
|
3
3
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
4
4
|
import { IntlProvider } from 'react-intl-next';
|
|
5
5
|
|
|
6
|
-
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
7
|
import { getCellsInColumn, selectTable } from '@atlaskit/editor-tables/utils';
|
|
8
8
|
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
9
|
+
import type { DocBuilder } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
9
10
|
import {
|
|
10
11
|
doc,
|
|
11
|
-
DocBuilder,
|
|
12
12
|
table,
|
|
13
13
|
tdCursor,
|
|
14
14
|
tdEmpty,
|
|
@@ -19,13 +19,10 @@ import { selectColumns, selectRows } from '@atlaskit/editor-test-helpers/table';
|
|
|
19
19
|
|
|
20
20
|
import tablePlugin from '../../../plugins/table-plugin';
|
|
21
21
|
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import FloatingDeleteButton, {
|
|
27
|
-
Props as FloatingDeleteButtonProps,
|
|
28
|
-
} from '../../../plugins/table/ui/FloatingDeleteButton';
|
|
22
|
+
import type { TablePluginState } from '../../../plugins/table/types';
|
|
23
|
+
import { TableCssClassName } from '../../../plugins/table/types';
|
|
24
|
+
import type { Props as FloatingDeleteButtonProps } from '../../../plugins/table/ui/FloatingDeleteButton';
|
|
25
|
+
import FloatingDeleteButton from '../../../plugins/table/ui/FloatingDeleteButton';
|
|
29
26
|
import * as tableColumnControlsUtils from '../../../plugins/table/utils/column-controls';
|
|
30
27
|
|
|
31
28
|
describe('Floating Delete Button', () => {
|
|
@@ -36,7 +33,9 @@ describe('Floating Delete Button', () => {
|
|
|
36
33
|
doc,
|
|
37
34
|
editorProps: {
|
|
38
35
|
allowTables: false,
|
|
39
|
-
dangerouslyAppendPlugins: {
|
|
36
|
+
dangerouslyAppendPlugins: {
|
|
37
|
+
__plugins: [tablePlugin({ config: undefined })],
|
|
38
|
+
},
|
|
40
39
|
},
|
|
41
40
|
pluginKey,
|
|
42
41
|
});
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { render, screen } from '@testing-library/react';
|
|
4
4
|
import { createIntl, IntlProvider } from 'react-intl-next';
|
|
5
5
|
|
|
6
|
-
import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
6
|
+
import type { UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
7
7
|
import {
|
|
8
8
|
ACTION,
|
|
9
9
|
ACTION_SUBJECT,
|
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
} from '@atlaskit/editor-common/analytics';
|
|
13
13
|
import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
|
|
14
14
|
import * as prosemirrorUtils from '@atlaskit/editor-prosemirror/utils';
|
|
15
|
-
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
15
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
16
16
|
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
17
|
+
import type { DocBuilder } from '@atlaskit/editor-test-helpers/doc-builder';
|
|
17
18
|
import {
|
|
18
19
|
doc,
|
|
19
|
-
DocBuilder,
|
|
20
20
|
table,
|
|
21
21
|
tdCursor,
|
|
22
22
|
tdEmpty,
|
|
@@ -33,11 +33,9 @@ import tablePlugin from '../../../plugins/table-plugin';
|
|
|
33
33
|
import { setEditorFocus, setTableRef } from '../../../plugins/table/commands';
|
|
34
34
|
import { getPluginState } from '../../../plugins/table/pm-plugins/plugin-factory';
|
|
35
35
|
import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
|
|
36
|
-
import { TablePluginState } from '../../../plugins/table/types';
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
Props as FloatingInsertButtonProps,
|
|
40
|
-
} from '../../../plugins/table/ui/FloatingInsertButton';
|
|
36
|
+
import type { TablePluginState } from '../../../plugins/table/types';
|
|
37
|
+
import type { Props as FloatingInsertButtonProps } from '../../../plugins/table/ui/FloatingInsertButton';
|
|
38
|
+
import { FloatingInsertButton } from '../../../plugins/table/ui/FloatingInsertButton';
|
|
41
39
|
|
|
42
40
|
jest.mock('@atlaskit/editor-prosemirror/utils', () => {
|
|
43
41
|
// Unblock prosemirror bump:
|
|
@@ -61,7 +59,9 @@ const editor = (doc: DocBuilder) =>
|
|
|
61
59
|
doc,
|
|
62
60
|
editorProps: {
|
|
63
61
|
allowTables: false,
|
|
64
|
-
dangerouslyAppendPlugins: {
|
|
62
|
+
dangerouslyAppendPlugins: {
|
|
63
|
+
__plugins: [tablePlugin({ config: undefined })],
|
|
64
|
+
},
|
|
65
65
|
},
|
|
66
66
|
pluginKey,
|
|
67
67
|
});
|
|
@@ -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
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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
|
|
|
@@ -104,15 +104,15 @@ export type TablePlugin = NextEditorPlugin<
|
|
|
104
104
|
}
|
|
105
105
|
>;
|
|
106
106
|
|
|
107
|
-
const tablesPlugin: TablePlugin = (options
|
|
107
|
+
const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
108
108
|
const editorViewRef: Record<'current', EditorView | null> = { current: null };
|
|
109
109
|
const defaultGetEditorContainerWidth: GetEditorContainerWidth = () => {
|
|
110
110
|
const defaultState = {
|
|
111
111
|
width: document?.body?.offsetWidth ?? 500,
|
|
112
112
|
};
|
|
113
|
-
return api?.
|
|
113
|
+
return api?.width.sharedState.currentState() ?? defaultState;
|
|
114
114
|
};
|
|
115
|
-
const editorAnalyticsAPI = api?.
|
|
115
|
+
const editorAnalyticsAPI = api?.analytics?.actions;
|
|
116
116
|
|
|
117
117
|
return {
|
|
118
118
|
name: 'table',
|
|
@@ -126,7 +126,7 @@ const tablesPlugin: TablePlugin = (options?: TablePluginOptions, api?) => {
|
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
return (
|
|
129
|
-
api?.
|
|
129
|
+
api?.contentInsertion?.actions?.insert({
|
|
130
130
|
state,
|
|
131
131
|
dispatch,
|
|
132
132
|
node,
|
|
@@ -162,6 +162,7 @@ const tablesPlugin: TablePlugin = (options?: TablePluginOptions, 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 = (options?: TablePluginOptions, api?) => {
|
|
|
179
180
|
pluginConfig(tableOptions),
|
|
180
181
|
defaultGetEditorContainerWidth,
|
|
181
182
|
getEditorFeatureFlags || defaultGetEditorFeatureFlags,
|
|
183
|
+
getIntl,
|
|
182
184
|
breakoutEnabled,
|
|
183
185
|
fullWidthEnabled,
|
|
184
186
|
tableResizingEnabled,
|
|
@@ -119,9 +119,9 @@ export const ResizableTableContainer = ({
|
|
|
119
119
|
const displayGuideline = useCallback(
|
|
120
120
|
(guidelines: GuidelineConfig[]) => {
|
|
121
121
|
return (
|
|
122
|
-
pluginInjectionApi?.
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
pluginInjectionApi?.guideline?.actions?.displayGuideline(editorView)({
|
|
123
|
+
guidelines,
|
|
124
|
+
}) ?? false
|
|
125
125
|
);
|
|
126
126
|
},
|
|
127
127
|
[pluginInjectionApi, editorView],
|
|
@@ -129,7 +129,7 @@ export const ResizableTableContainer = ({
|
|
|
129
129
|
|
|
130
130
|
const attachAnalyticsEvent = useCallback(
|
|
131
131
|
(payload: TableEventPayload) => {
|
|
132
|
-
return pluginInjectionApi?.
|
|
132
|
+
return pluginInjectionApi?.analytics?.actions.attachAnalyticsEvent(
|
|
133
133
|
payload,
|
|
134
134
|
);
|
|
135
135
|
},
|
|
@@ -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 {
|
|
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.
|
|
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
|
-
(
|
|
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(
|
|
41
|
-
|
|
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 {
|
|
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: () => {
|