@atlaskit/editor-plugin-table 2.12.6 → 2.13.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 +10 -0
- package/dist/cjs/plugins/table/index.js +2 -0
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +6 -1
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +23 -5
- package/dist/es2019/plugins/table/index.js +3 -0
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +6 -1
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +24 -6
- package/dist/esm/plugins/table/index.js +3 -0
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +6 -1
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +24 -6
- package/dist/types/plugins/table/index.d.ts +9 -2
- package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/index.d.ts +9 -2
- package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +2 -1
- package/package.json +2 -2
- package/report.api.md +14 -0
- package/src/__tests__/unit/analytics.ts +2 -0
- package/src/__tests__/unit/collab.ts +2 -0
- package/src/__tests__/unit/commands/go-to-next-cell.ts +2 -0
- package/src/__tests__/unit/commands/insert.ts +2 -0
- package/src/__tests__/unit/commands/misc.ts +2 -0
- package/src/__tests__/unit/commands/sort.ts +4 -0
- package/src/__tests__/unit/commands.ts +2 -0
- package/src/__tests__/unit/copy-paste.ts +2 -0
- package/src/__tests__/unit/event-handlers/index.ts +3 -0
- package/src/__tests__/unit/event-handlers.ts +3 -0
- package/src/__tests__/unit/fix-tables.ts +2 -0
- package/src/__tests__/unit/get-toolbar-config.ts +2 -0
- package/src/__tests__/unit/handlers.ts +2 -0
- package/src/__tests__/unit/hover-selection.ts +2 -0
- package/src/__tests__/unit/index.ts +2 -0
- package/src/__tests__/unit/layout.ts +2 -0
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +58 -0
- package/src/__tests__/unit/nodeviews/cell.ts +2 -0
- package/src/__tests__/unit/nodeviews/table.ts +2 -0
- package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +2 -0
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +3 -0
- package/src/__tests__/unit/pm-plugins/main.ts +2 -0
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +2 -0
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +3 -0
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +2 -0
- package/src/__tests__/unit/pm-plugins/table-width.ts +99 -0
- package/src/__tests__/unit/sort-column.ts +2 -0
- package/src/__tests__/unit/toolbar.ts +2 -0
- package/src/__tests__/unit/transforms/delete-columns.ts +2 -0
- package/src/__tests__/unit/transforms/delete-rows.ts +2 -0
- package/src/__tests__/unit/transforms/merging.ts +2 -0
- package/src/__tests__/unit/ui/ContextualMenu.tsx +2 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +2 -0
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +2 -0
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +4 -2
- package/src/__tests__/unit/ui/RowControls.tsx +2 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +2 -0
- package/src/__tests__/unit/undo-redo.ts +2 -0
- package/src/__tests__/unit/utils/collapse.ts +2 -0
- package/src/__tests__/unit/utils/nodes.ts +2 -0
- package/src/__tests__/unit/utils/row-controls.ts +2 -0
- package/src/__tests__/unit/utils.ts +2 -0
- package/src/plugins/table/index.tsx +13 -0
- package/src/plugins/table/nodeviews/TableContainer.tsx +12 -0
- package/src/plugins/table/nodeviews/TableResizer.tsx +36 -5
- package/src/plugins/table/nodeviews/table.tsx +0 -1
- package/tmp/api-report-tmp.d.ts +12 -1
- package/tsconfig.app.json +0 -3
- package/tsconfig.dev.json +6 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import selectionPlugin from '@atlaskit/editor-core/src/plugins/selection';
|
|
1
2
|
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
2
3
|
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
3
4
|
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
@@ -43,6 +44,7 @@ describe('table plugin: utils', () => {
|
|
|
43
44
|
.add(contentInsertionPlugin)
|
|
44
45
|
.add(widthPlugin)
|
|
45
46
|
.add(guidelinePlugin)
|
|
47
|
+
.add(selectionPlugin)
|
|
46
48
|
.add(tablePlugin);
|
|
47
49
|
|
|
48
50
|
const editor = (doc: DocBuilder) =>
|
|
@@ -24,10 +24,12 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
24
24
|
import type { EditorSelectionAPI } from '@atlaskit/editor-common/selection';
|
|
25
25
|
import type {
|
|
26
26
|
Command,
|
|
27
|
+
EditorCommand,
|
|
27
28
|
EditorPlugin,
|
|
28
29
|
GetEditorContainerWidth,
|
|
29
30
|
GetEditorFeatureFlags,
|
|
30
31
|
NextEditorPlugin,
|
|
32
|
+
OptionalPlugin,
|
|
31
33
|
} from '@atlaskit/editor-common/types';
|
|
32
34
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
33
35
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
@@ -86,6 +88,16 @@ interface TablePluginOptions {
|
|
|
86
88
|
|
|
87
89
|
type InsertTableAction = (analyticsPayload: AnalyticsEventPayload) => Command;
|
|
88
90
|
|
|
91
|
+
// TODO: duplicated SelectionPlugin type as it's still in editor-core, doing this avoid
|
|
92
|
+
// circular dependencies
|
|
93
|
+
type SelectionPlugin = NextEditorPlugin<
|
|
94
|
+
'selection',
|
|
95
|
+
{
|
|
96
|
+
pluginConfiguration: unknown;
|
|
97
|
+
commands: { displayGapCursor: (toggle: boolean) => EditorCommand };
|
|
98
|
+
}
|
|
99
|
+
>;
|
|
100
|
+
|
|
89
101
|
const defaultGetEditorFeatureFlags = () => ({});
|
|
90
102
|
|
|
91
103
|
export type TablePlugin = NextEditorPlugin<
|
|
@@ -100,6 +112,7 @@ export type TablePlugin = NextEditorPlugin<
|
|
|
100
112
|
ContentInsertionPlugin,
|
|
101
113
|
WidthPlugin,
|
|
102
114
|
GuidelinePlugin,
|
|
115
|
+
OptionalPlugin<SelectionPlugin>,
|
|
103
116
|
];
|
|
104
117
|
}
|
|
105
118
|
>;
|
|
@@ -136,6 +136,17 @@ export const ResizableTableContainer = ({
|
|
|
136
136
|
[pluginInjectionApi],
|
|
137
137
|
);
|
|
138
138
|
|
|
139
|
+
const displayGapCursor = useCallback(
|
|
140
|
+
(toggle) => {
|
|
141
|
+
return (
|
|
142
|
+
pluginInjectionApi?.core?.actions.execute(
|
|
143
|
+
pluginInjectionApi?.selection?.commands.displayGapCursor(toggle),
|
|
144
|
+
) ?? false
|
|
145
|
+
);
|
|
146
|
+
},
|
|
147
|
+
[pluginInjectionApi],
|
|
148
|
+
);
|
|
149
|
+
|
|
139
150
|
const tableWidth = getTableContainerWidth(node);
|
|
140
151
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
141
152
|
const responsiveContainerWidth = containerWidth - 76;
|
|
@@ -167,6 +178,7 @@ export const ResizableTableContainer = ({
|
|
|
167
178
|
tableRef={tableRef}
|
|
168
179
|
displayGuideline={displayGuideline}
|
|
169
180
|
attachAnalyticsEvent={attachAnalyticsEvent}
|
|
181
|
+
displayGapCursor={displayGapCursor}
|
|
170
182
|
>
|
|
171
183
|
<InnerContainer className={className} node={node}>
|
|
172
184
|
{children}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { PropsWithChildren } from 'react';
|
|
2
|
-
import React, {
|
|
2
|
+
import React, {
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
3
9
|
|
|
4
10
|
import rafSchd from 'raf-schd';
|
|
5
11
|
import { defineMessages, useIntl } from 'react-intl-next';
|
|
@@ -51,6 +57,7 @@ interface TableResizerProps {
|
|
|
51
57
|
attachAnalyticsEvent: (
|
|
52
58
|
payload: TableEventPayload,
|
|
53
59
|
) => ((tr: Transaction) => boolean) | undefined;
|
|
60
|
+
displayGapCursor: (toggle: boolean) => boolean;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
const messages = defineMessages({
|
|
@@ -134,8 +141,11 @@ export const TableResizer = ({
|
|
|
134
141
|
tableRef,
|
|
135
142
|
displayGuideline,
|
|
136
143
|
attachAnalyticsEvent,
|
|
144
|
+
displayGapCursor,
|
|
137
145
|
}: PropsWithChildren<TableResizerProps>) => {
|
|
138
146
|
const currentGap = useRef(0);
|
|
147
|
+
// track resizing state - use ref over state to avoid re-render
|
|
148
|
+
const isResizing = useRef(false);
|
|
139
149
|
const [snappingEnabled, setSnappingEnabled] = useState(false);
|
|
140
150
|
const { formatMessage } = useIntl();
|
|
141
151
|
|
|
@@ -176,22 +186,41 @@ export const TableResizer = ({
|
|
|
176
186
|
[snappingEnabled],
|
|
177
187
|
);
|
|
178
188
|
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
return () => {
|
|
191
|
+
// only bring back the cursor if this table was deleted - i.e. if a user was resizing, then another
|
|
192
|
+
// deleted this table
|
|
193
|
+
if (isResizing.current) {
|
|
194
|
+
displayGapCursor(true);
|
|
195
|
+
displayGuideline([]);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}, [displayGuideline, displayGapCursor]);
|
|
199
|
+
|
|
179
200
|
const handleResizeStart = useCallback(() => {
|
|
180
201
|
startMeasure();
|
|
181
|
-
|
|
202
|
+
isResizing.current = true;
|
|
182
203
|
const {
|
|
183
204
|
dispatch,
|
|
184
205
|
state: { tr },
|
|
185
206
|
} = editorView;
|
|
207
|
+
tr.setMeta(tableWidthPluginKey, { resizing: true });
|
|
208
|
+
displayGapCursor(false);
|
|
186
209
|
|
|
187
|
-
dispatch(tr
|
|
210
|
+
dispatch(tr);
|
|
188
211
|
|
|
189
212
|
const visibleGuidelines = getVisibleGuidelines(
|
|
190
213
|
defaultGuidelines,
|
|
191
214
|
containerWidth,
|
|
192
215
|
);
|
|
193
216
|
setSnappingEnabled(displayGuideline(visibleGuidelines));
|
|
194
|
-
}, [
|
|
217
|
+
}, [
|
|
218
|
+
displayGapCursor,
|
|
219
|
+
displayGuideline,
|
|
220
|
+
editorView,
|
|
221
|
+
startMeasure,
|
|
222
|
+
containerWidth,
|
|
223
|
+
]);
|
|
195
224
|
|
|
196
225
|
const handleResize = useCallback(
|
|
197
226
|
(originalState, delta) => {
|
|
@@ -242,6 +271,7 @@ export const TableResizer = ({
|
|
|
242
271
|
|
|
243
272
|
const handleResizeStop = useCallback<HandleResize>(
|
|
244
273
|
(originalState, delta) => {
|
|
274
|
+
isResizing.current = false;
|
|
245
275
|
const newWidth = originalState.width + delta.width;
|
|
246
276
|
const { state, dispatch } = editorView;
|
|
247
277
|
const pos = getPos();
|
|
@@ -287,7 +317,7 @@ export const TableResizer = ({
|
|
|
287
317
|
}),
|
|
288
318
|
)?.(tr);
|
|
289
319
|
}
|
|
290
|
-
|
|
320
|
+
displayGapCursor(true);
|
|
291
321
|
dispatch(tr);
|
|
292
322
|
|
|
293
323
|
// Hide guidelines when resizing stops
|
|
@@ -298,6 +328,7 @@ export const TableResizer = ({
|
|
|
298
328
|
return newWidth;
|
|
299
329
|
},
|
|
300
330
|
[
|
|
331
|
+
displayGapCursor,
|
|
301
332
|
updateWidth,
|
|
302
333
|
editorView,
|
|
303
334
|
getPos,
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -8,10 +8,12 @@ import type { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
|
|
|
8
8
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
9
9
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
10
10
|
import type { ContentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
11
|
+
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
11
12
|
import type { EditorSelectionAPI } from '@atlaskit/editor-common/selection';
|
|
12
13
|
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
13
14
|
import type { GuidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
14
15
|
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
16
|
+
import type { OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
15
17
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
16
18
|
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
17
19
|
|
|
@@ -69,6 +71,14 @@ interface PluginConfig {
|
|
|
69
71
|
tableRenderOptimization?: boolean;
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
// @public (undocumented)
|
|
75
|
+
type SelectionPlugin = NextEditorPlugin<'selection', {
|
|
76
|
+
pluginConfiguration: unknown;
|
|
77
|
+
commands: {
|
|
78
|
+
displayGapCursor: (toggle: boolean) => EditorCommand;
|
|
79
|
+
};
|
|
80
|
+
}>;
|
|
81
|
+
|
|
72
82
|
// @public (undocumented)
|
|
73
83
|
export type TablePlugin = NextEditorPlugin<'table', {
|
|
74
84
|
pluginConfiguration: TablePluginOptions | undefined;
|
|
@@ -79,7 +89,8 @@ export type TablePlugin = NextEditorPlugin<'table', {
|
|
|
79
89
|
AnalyticsPlugin,
|
|
80
90
|
ContentInsertionPlugin,
|
|
81
91
|
WidthPlugin,
|
|
82
|
-
GuidelinePlugin
|
|
92
|
+
GuidelinePlugin,
|
|
93
|
+
OptionalPlugin<SelectionPlugin>
|
|
83
94
|
];
|
|
84
95
|
}>;
|
|
85
96
|
|
package/tsconfig.app.json
CHANGED
package/tsconfig.dev.json
CHANGED
|
@@ -45,6 +45,9 @@
|
|
|
45
45
|
{
|
|
46
46
|
"path": "../../design-system/button/tsconfig.app.json"
|
|
47
47
|
},
|
|
48
|
+
{
|
|
49
|
+
"path": "../../../build/website/docs/tsconfig.app.json"
|
|
50
|
+
},
|
|
48
51
|
{
|
|
49
52
|
"path": "../editor-common/tsconfig.app.json"
|
|
50
53
|
},
|
|
@@ -72,9 +75,6 @@
|
|
|
72
75
|
{
|
|
73
76
|
"path": "../editor-plugin-width/tsconfig.app.json"
|
|
74
77
|
},
|
|
75
|
-
{
|
|
76
|
-
"path": "../editor-prosemirror/tsconfig.app.json"
|
|
77
|
-
},
|
|
78
78
|
{
|
|
79
79
|
"path": "../editor-shared-styles/tsconfig.app.json"
|
|
80
80
|
},
|
|
@@ -99,6 +99,9 @@
|
|
|
99
99
|
{
|
|
100
100
|
"path": "../../design-system/theme/tsconfig.app.json"
|
|
101
101
|
},
|
|
102
|
+
{
|
|
103
|
+
"path": "../../design-system/tokens/tsconfig.app.json"
|
|
104
|
+
},
|
|
102
105
|
{
|
|
103
106
|
"path": "../../../build/test-tooling/visual-regression/tsconfig.app.json"
|
|
104
107
|
},
|