@atlaskit/editor-plugin-table 5.4.6 → 5.4.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 +12 -0
- package/dist/cjs/plugins/table/commands/insert.js +12 -2
- package/dist/cjs/plugins/table/commands/misc.js +63 -13
- package/dist/cjs/plugins/table/index.js +46 -35
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +14 -20
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +1 -1
- package/dist/cjs/plugins/table/nodeviews/table.js +3 -1
- package/dist/cjs/plugins/table/pm-plugins/analytics/actions.js +14 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/commands.js +45 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/plugin-factory.js +13 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/plugin-key.js +8 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/plugin.js +74 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/reducer.js +26 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/types.js +13 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/utils/moved-event.js +38 -0
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/cjs/plugins/table/pm-plugins/main.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/table-analytics.js +1 -1
- package/dist/cjs/plugins/table/types.js +2 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/cjs/plugins/table/ui/common-styles.js +6 -9
- package/dist/cjs/plugins/table/ui/ui-styles.js +12 -16
- package/dist/cjs/plugins/table/utils/decoration.js +20 -25
- package/dist/es2019/plugins/table/commands/insert.js +12 -3
- package/dist/es2019/plugins/table/commands/misc.js +54 -4
- package/dist/es2019/plugins/table/index.js +14 -4
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +15 -21
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/table.js +3 -1
- package/dist/es2019/plugins/table/pm-plugins/analytics/actions.js +8 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/commands.js +33 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/plugin-factory.js +8 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/plugin-key.js +2 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/plugin.js +72 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/reducer.js +21 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/types.js +7 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/utils/moved-event.js +30 -0
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/table-analytics.js +1 -1
- package/dist/es2019/plugins/table/types.js +2 -1
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/es2019/plugins/table/ui/common-styles.js +20 -20
- package/dist/es2019/plugins/table/ui/ui-styles.js +18 -21
- package/dist/es2019/plugins/table/utils/decoration.js +20 -25
- package/dist/esm/plugins/table/commands/insert.js +12 -3
- package/dist/esm/plugins/table/commands/misc.js +61 -13
- package/dist/esm/plugins/table/index.js +43 -32
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +15 -21
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +1 -1
- package/dist/esm/plugins/table/nodeviews/table.js +3 -1
- package/dist/esm/plugins/table/pm-plugins/analytics/actions.js +8 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/commands.js +39 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/plugin-factory.js +8 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/plugin-key.js +2 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/plugin.js +68 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/reducer.js +19 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/types.js +7 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/utils/moved-event.js +31 -0
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/table-analytics.js +1 -1
- package/dist/esm/plugins/table/types.js +2 -1
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/esm/plugins/table/ui/common-styles.js +6 -9
- package/dist/esm/plugins/table/ui/ui-styles.js +12 -16
- package/dist/esm/plugins/table/utils/decoration.js +20 -25
- package/dist/types/plugins/table/commands/misc.d.ts +5 -1
- package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +2 -0
- package/dist/types/plugins/table/nodeviews/table.d.ts +2 -1
- package/dist/types/plugins/table/nodeviews/types.d.ts +2 -0
- package/dist/types/plugins/table/pm-plugins/analytics/actions.d.ts +17 -0
- package/dist/types/plugins/table/pm-plugins/analytics/commands.d.ts +5 -0
- package/dist/types/plugins/table/pm-plugins/analytics/plugin-factory.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/analytics/plugin-key.d.ts +3 -0
- package/dist/types/plugins/table/pm-plugins/analytics/plugin.d.ts +4 -0
- package/dist/types/plugins/table/pm-plugins/analytics/reducer.d.ts +3 -0
- package/dist/types/plugins/table/pm-plugins/analytics/types.d.ts +11 -0
- package/dist/types/plugins/table/pm-plugins/analytics/utils/moved-event.d.ts +6 -0
- package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
- package/dist/types/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
- package/dist/types/plugins/table/types.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/actions.d.ts +17 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/commands.d.ts +5 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin-factory.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin.d.ts +4 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/reducer.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/types.d.ts +11 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/utils/moved-event.d.ts +6 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
- package/dist/types-ts4.5/plugins/table/types.d.ts +2 -1
- package/package.json +4 -1
- package/src/__tests__/unit/event-handlers.ts +37 -38
- package/src/__tests__/unit/index-with-fake-timers.ts +1 -0
- package/src/__tests__/unit/nodeviews/table.ts +1 -0
- package/src/__tests__/unit/pm-plugins/analytics.ts +327 -0
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +46 -36
- package/src/plugins/table/commands/insert.ts +23 -2
- package/src/plugins/table/commands/misc.ts +93 -8
- package/src/plugins/table/index.tsx +13 -6
- package/src/plugins/table/nodeviews/TableComponent.tsx +35 -44
- package/src/plugins/table/nodeviews/TableResizer.tsx +1 -2
- package/src/plugins/table/nodeviews/table.tsx +4 -0
- package/src/plugins/table/nodeviews/types.ts +2 -0
- package/src/plugins/table/pm-plugins/analytics/actions.ts +23 -0
- package/src/plugins/table/pm-plugins/analytics/commands.ts +53 -0
- package/src/plugins/table/pm-plugins/analytics/plugin-factory.ts +7 -0
- package/src/plugins/table/pm-plugins/analytics/plugin-key.ts +7 -0
- package/src/plugins/table/pm-plugins/analytics/plugin.ts +98 -0
- package/src/plugins/table/pm-plugins/analytics/reducer.ts +27 -0
- package/src/plugins/table/pm-plugins/analytics/types.ts +20 -0
- package/src/plugins/table/pm-plugins/analytics/utils/moved-event.ts +51 -0
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +7 -2
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +20 -11
- package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +2 -4
- package/src/plugins/table/pm-plugins/decorations/utils/types.ts +14 -7
- package/src/plugins/table/pm-plugins/main.ts +1 -0
- package/src/plugins/table/pm-plugins/table-analytics.ts +1 -1
- package/src/plugins/table/types.ts +2 -1
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +73 -67
- package/src/plugins/table/ui/common-styles.ts +20 -23
- package/src/plugins/table/ui/ui-styles.ts +18 -21
- package/src/plugins/table/utils/decoration.ts +27 -32
- package/tsconfig.dev.json +3 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
3
|
+
import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
+
import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
|
|
5
|
+
import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
6
|
+
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
7
|
+
import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
8
|
+
import { widthPlugin } from '@atlaskit/editor-plugin-width';
|
|
9
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
10
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
11
|
+
import { __serializeForClipboard } from '@atlaskit/editor-prosemirror/view';
|
|
12
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
13
|
+
import {
|
|
14
|
+
createProsemirrorEditorFactory,
|
|
15
|
+
Preset,
|
|
16
|
+
} from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
17
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
18
|
+
import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
|
|
19
|
+
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
20
|
+
import dispatchPasteEvent from '@atlaskit/editor-test-helpers/dispatch-paste-event';
|
|
21
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
22
|
+
import {
|
|
23
|
+
doc,
|
|
24
|
+
p,
|
|
25
|
+
table,
|
|
26
|
+
td,
|
|
27
|
+
tr,
|
|
28
|
+
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
29
|
+
import { ffTest } from '@atlassian/feature-flags-test-utils';
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line @atlassian/tangerine/import/no-relative-package-imports
|
|
32
|
+
import tablePlugin from '../../../plugins/table';
|
|
33
|
+
import {
|
|
34
|
+
insertColumn,
|
|
35
|
+
insertRow,
|
|
36
|
+
selectColumn,
|
|
37
|
+
selectRow,
|
|
38
|
+
} from '../../../plugins/table/commands';
|
|
39
|
+
import { pluginKey } from '../../../plugins/table/pm-plugins/analytics/plugin-key';
|
|
40
|
+
|
|
41
|
+
jest.mock('@atlaskit/platform-feature-flags', () => ({
|
|
42
|
+
getBooleanFF: jest.fn().mockImplementation(() => false),
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
describe('analytics', () => {
|
|
46
|
+
const createEditor = createProsemirrorEditorFactory();
|
|
47
|
+
const editor = (doc: DocBuilder) => {
|
|
48
|
+
return createEditor({
|
|
49
|
+
doc,
|
|
50
|
+
preset: new Preset<LightEditorPlugin>()
|
|
51
|
+
.add([featureFlagsPlugin, {}])
|
|
52
|
+
.add([analyticsPlugin, {}])
|
|
53
|
+
.add(contentInsertionPlugin)
|
|
54
|
+
.add(widthPlugin)
|
|
55
|
+
.add(guidelinePlugin)
|
|
56
|
+
.add(selectionPlugin)
|
|
57
|
+
.add([
|
|
58
|
+
tablePlugin,
|
|
59
|
+
{
|
|
60
|
+
tableOptions: {
|
|
61
|
+
allowHeaderRow: true,
|
|
62
|
+
allowMergeCells: true,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
]),
|
|
66
|
+
pluginKey,
|
|
67
|
+
attachTo: document.body,
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
describe('rowOrColumnMoved', () => {
|
|
72
|
+
describe('should update plugin state when row is copied', () => {
|
|
73
|
+
ffTest(
|
|
74
|
+
'platform.editor.table.analytics-plugin-moved-event',
|
|
75
|
+
() => {
|
|
76
|
+
const { editorView } = editor(
|
|
77
|
+
doc(
|
|
78
|
+
table()(
|
|
79
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
|
|
80
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
__serializeForClipboard(
|
|
86
|
+
editorView,
|
|
87
|
+
editorView.state.selection.content(),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const { rowOrColumnMoved } =
|
|
91
|
+
pluginKey.getState(editorView.state) || {};
|
|
92
|
+
|
|
93
|
+
expect(rowOrColumnMoved).toEqual({
|
|
94
|
+
type: 'row',
|
|
95
|
+
numberOfCells: 2,
|
|
96
|
+
currentActions: ['copyOrCut'],
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
() => {
|
|
100
|
+
const { editorView } = editor(
|
|
101
|
+
doc(
|
|
102
|
+
table()(
|
|
103
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
|
|
104
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
105
|
+
),
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
__serializeForClipboard(
|
|
110
|
+
editorView,
|
|
111
|
+
editorView.state.selection.content(),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const { rowOrColumnMoved } =
|
|
115
|
+
pluginKey.getState(editorView.state) || {};
|
|
116
|
+
|
|
117
|
+
expect(rowOrColumnMoved).toEqual(undefined);
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('should update plugin state when column is copied', () => {
|
|
123
|
+
ffTest(
|
|
124
|
+
'platform.editor.table.analytics-plugin-moved-event',
|
|
125
|
+
() => {
|
|
126
|
+
const { editorView } = editor(
|
|
127
|
+
doc(
|
|
128
|
+
table()(
|
|
129
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2'))),
|
|
130
|
+
tr(td({})(p('b1{cell>}')), td({})(p('b2'))),
|
|
131
|
+
),
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
__serializeForClipboard(
|
|
136
|
+
editorView,
|
|
137
|
+
editorView.state.selection.content(),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const { rowOrColumnMoved } =
|
|
141
|
+
pluginKey.getState(editorView.state) || {};
|
|
142
|
+
|
|
143
|
+
expect(rowOrColumnMoved).toEqual({
|
|
144
|
+
type: 'column',
|
|
145
|
+
numberOfCells: 2,
|
|
146
|
+
currentActions: ['copyOrCut'],
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
() => {
|
|
150
|
+
const { editorView } = editor(
|
|
151
|
+
doc(
|
|
152
|
+
table()(
|
|
153
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2'))),
|
|
154
|
+
tr(td({})(p('b1{cell>}')), td({})(p('b2'))),
|
|
155
|
+
),
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
__serializeForClipboard(
|
|
160
|
+
editorView,
|
|
161
|
+
editorView.state.selection.content(),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const { rowOrColumnMoved } =
|
|
165
|
+
pluginKey.getState(editorView.state) || {};
|
|
166
|
+
|
|
167
|
+
expect(rowOrColumnMoved).toEqual(undefined);
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('should update plugin state when row is inserted and then copied', () => {
|
|
173
|
+
ffTest(
|
|
174
|
+
'platform.editor.table.analytics-plugin-moved-event',
|
|
175
|
+
() => {
|
|
176
|
+
const { editorView } = editor(
|
|
177
|
+
doc(
|
|
178
|
+
table()(
|
|
179
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
|
|
180
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
insertRow(0, false)(editorView.state, editorView.dispatch);
|
|
186
|
+
selectRow(0)(editorView.state, editorView.dispatch);
|
|
187
|
+
|
|
188
|
+
__serializeForClipboard(
|
|
189
|
+
editorView,
|
|
190
|
+
editorView.state.selection.content(),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const { rowOrColumnMoved } =
|
|
194
|
+
pluginKey.getState(editorView.state) || {};
|
|
195
|
+
|
|
196
|
+
expect(rowOrColumnMoved).toEqual({
|
|
197
|
+
type: 'row',
|
|
198
|
+
numberOfCells: 2,
|
|
199
|
+
currentActions: ['addRowOrColumn', 'copyOrCut'],
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
() => {
|
|
203
|
+
const { editorView } = editor(
|
|
204
|
+
doc(
|
|
205
|
+
table()(
|
|
206
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
|
|
207
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
208
|
+
),
|
|
209
|
+
),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const { rowOrColumnMoved } =
|
|
213
|
+
pluginKey.getState(editorView.state) || {};
|
|
214
|
+
expect(rowOrColumnMoved).toEqual(undefined);
|
|
215
|
+
},
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('should update plugin state when column is inserted and then copied', () => {
|
|
220
|
+
ffTest(
|
|
221
|
+
'platform.editor.table.analytics-plugin-moved-event',
|
|
222
|
+
() => {
|
|
223
|
+
const { editorView } = editor(
|
|
224
|
+
doc(
|
|
225
|
+
table()(
|
|
226
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
|
|
227
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
228
|
+
),
|
|
229
|
+
),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
insertColumn(
|
|
233
|
+
jest.fn().mockReturnValue({ containerWidth: { width: 760 } }),
|
|
234
|
+
)(0)(editorView.state, editorView.dispatch, editorView);
|
|
235
|
+
selectColumn(0)(editorView.state, editorView.dispatch);
|
|
236
|
+
|
|
237
|
+
__serializeForClipboard(
|
|
238
|
+
editorView,
|
|
239
|
+
editorView.state.selection.content(),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const { rowOrColumnMoved } =
|
|
243
|
+
pluginKey.getState(editorView.state) || {};
|
|
244
|
+
|
|
245
|
+
expect(rowOrColumnMoved).toEqual({
|
|
246
|
+
type: 'column',
|
|
247
|
+
numberOfCells: 2,
|
|
248
|
+
currentActions: ['addRowOrColumn', 'copyOrCut'],
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
() => {
|
|
252
|
+
const { editorView } = editor(
|
|
253
|
+
doc(
|
|
254
|
+
table()(
|
|
255
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
|
|
256
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
257
|
+
),
|
|
258
|
+
),
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const { rowOrColumnMoved } =
|
|
262
|
+
pluginKey.getState(editorView.state) || {};
|
|
263
|
+
expect(rowOrColumnMoved).toEqual(undefined);
|
|
264
|
+
},
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('should remove plugin state when row is inserted and then copied and pasted', () => {
|
|
269
|
+
ffTest(
|
|
270
|
+
'platform.editor.table.analytics-plugin-moved-event',
|
|
271
|
+
() => {
|
|
272
|
+
const { editorView } = editor(
|
|
273
|
+
doc(
|
|
274
|
+
table()(
|
|
275
|
+
tr(td({})(p('a1')), td({})(p('a2'))),
|
|
276
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
277
|
+
),
|
|
278
|
+
),
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
insertRow(0, false)(editorView.state, editorView.dispatch);
|
|
282
|
+
selectRow(0)(editorView.state, editorView.dispatch);
|
|
283
|
+
|
|
284
|
+
const { dom, text } = __serializeForClipboard(
|
|
285
|
+
editorView,
|
|
286
|
+
editorView.state.selection.content(),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
// place cursor in first cell
|
|
290
|
+
editorView.dispatch(
|
|
291
|
+
editorView.state.tr.setSelection(
|
|
292
|
+
new TextSelection(
|
|
293
|
+
editorView.state.doc.resolve(4),
|
|
294
|
+
editorView.state.doc.resolve(4),
|
|
295
|
+
),
|
|
296
|
+
),
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
300
|
+
|
|
301
|
+
const { rowOrColumnMoved } =
|
|
302
|
+
pluginKey.getState(editorView.state) || {};
|
|
303
|
+
|
|
304
|
+
expect(rowOrColumnMoved).toEqual({
|
|
305
|
+
type: undefined,
|
|
306
|
+
numberOfCells: undefined,
|
|
307
|
+
currentActions: [],
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
() => {
|
|
311
|
+
const { editorView } = editor(
|
|
312
|
+
doc(
|
|
313
|
+
table()(
|
|
314
|
+
tr(td({})(p('{<cell}a1')), td({})(p('a2{cell>}'))),
|
|
315
|
+
tr(td({})(p('b1')), td({})(p('b2'))),
|
|
316
|
+
),
|
|
317
|
+
),
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const { rowOrColumnMoved } =
|
|
321
|
+
pluginKey.getState(editorView.state) || {};
|
|
322
|
+
expect(rowOrColumnMoved).toEqual(undefined);
|
|
323
|
+
},
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
});
|
|
@@ -9,47 +9,57 @@ import {
|
|
|
9
9
|
tdEmpty,
|
|
10
10
|
tr,
|
|
11
11
|
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
12
|
-
import {
|
|
12
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
13
13
|
|
|
14
14
|
import { buildColumnControlsDecorations } from '../../../../plugins/table/pm-plugins/decorations/utils';
|
|
15
15
|
import { TableDecorations } from '../../../../plugins/table/types';
|
|
16
16
|
|
|
17
|
+
// Mock Feature flags instead of using ffTest because we don't use the feature flag directly
|
|
18
|
+
jest.mock('@atlaskit/platform-feature-flags', () => ({
|
|
19
|
+
getBooleanFF: jest.fn().mockImplementation(() => false),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
(getBooleanFF as jest.Mock).mockReset();
|
|
24
|
+
});
|
|
25
|
+
|
|
17
26
|
describe('tables: column controls decorations', () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
'platform.editor.table.drag-and-drop',
|
|
21
|
-
() => {
|
|
22
|
-
const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
|
|
23
|
-
const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
|
|
24
|
-
const nextDecorationSet = buildColumnControlsDecorations({
|
|
25
|
-
decorationSet: DecorationSet.empty,
|
|
26
|
-
tr: state.tr,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const decorations = nextDecorationSet.find(
|
|
30
|
-
undefined,
|
|
31
|
-
undefined,
|
|
32
|
-
(spec: any) => spec.key.indexOf(decorationKey) > -1,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
expect(decorations).toHaveLength(0);
|
|
36
|
-
},
|
|
37
|
-
() => {
|
|
38
|
-
const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
|
|
39
|
-
const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
|
|
40
|
-
const nextDecorationSet = buildColumnControlsDecorations({
|
|
41
|
-
decorationSet: DecorationSet.empty,
|
|
42
|
-
tr: state.tr,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const decorations = nextDecorationSet.find(
|
|
46
|
-
undefined,
|
|
47
|
-
undefined,
|
|
48
|
-
(spec: any) => spec.key.indexOf(decorationKey) > -1,
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
expect(decorations).toHaveLength(2);
|
|
52
|
-
},
|
|
27
|
+
it(`should return an empty decorationSet ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop is enabled`, () => {
|
|
28
|
+
(getBooleanFF as jest.Mock).mockImplementation(
|
|
29
|
+
(name) => name === 'platform.editor.table.drag-and-drop',
|
|
53
30
|
);
|
|
31
|
+
const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
|
|
32
|
+
const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
|
|
33
|
+
const nextDecorationSet = buildColumnControlsDecorations({
|
|
34
|
+
decorationSet: DecorationSet.empty,
|
|
35
|
+
tr: state.tr,
|
|
36
|
+
options: { isDragAndDropEnabled: true },
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const decorations = nextDecorationSet.find(
|
|
40
|
+
undefined,
|
|
41
|
+
undefined,
|
|
42
|
+
(spec: any) => spec.key.indexOf(decorationKey) > -1,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(decorations).toHaveLength(0);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it(`should return an empty decorationSet ${TableDecorations.COLUMN_CONTROLS_DECORATIONS} type when drag and drop is disabled`, () => {
|
|
49
|
+
const decorationKey = TableDecorations.COLUMN_CONTROLS_DECORATIONS;
|
|
50
|
+
const state = createEditorState(doc(table()(tr(tdCursor, tdEmpty))));
|
|
51
|
+
const nextDecorationSet = buildColumnControlsDecorations({
|
|
52
|
+
decorationSet: DecorationSet.empty,
|
|
53
|
+
tr: state.tr,
|
|
54
|
+
options: { isDragAndDropEnabled: false },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const decorations = nextDecorationSet.find(
|
|
58
|
+
undefined,
|
|
59
|
+
undefined,
|
|
60
|
+
(spec: any) => spec.key.indexOf(decorationKey) > -1,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(decorations).toHaveLength(2);
|
|
54
64
|
});
|
|
55
65
|
});
|
|
@@ -17,14 +17,14 @@ import {
|
|
|
17
17
|
findTable,
|
|
18
18
|
selectedRect,
|
|
19
19
|
} from '@atlaskit/editor-tables/utils';
|
|
20
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
20
21
|
|
|
22
|
+
import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
|
|
21
23
|
import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
22
24
|
import { rescaleColumns } from '../transforms/column-width';
|
|
23
25
|
import { checkIfHeaderRowEnabled, copyPreviousRow } from '../utils';
|
|
24
26
|
import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
|
|
25
27
|
|
|
26
|
-
// #endregion
|
|
27
|
-
|
|
28
28
|
function addColumnAtCustomStep(column: number) {
|
|
29
29
|
return (tr: Transaction) => {
|
|
30
30
|
const table = findTable(tr.selection);
|
|
@@ -55,9 +55,21 @@ export function addColumnAt(getEditorContainerWidth: GetEditorContainerWidth) {
|
|
|
55
55
|
updatedTr,
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
getBooleanFF('platform.editor.table.analytics-plugin-moved-event') &&
|
|
61
|
+
view
|
|
62
|
+
) {
|
|
63
|
+
updatedTr = updateRowOrColumnMovedTransform(
|
|
64
|
+
{ type: 'column' },
|
|
65
|
+
'addRowOrColumn',
|
|
66
|
+
)(view.state, updatedTr);
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
59
70
|
name: TABLE_OVERFLOW_CHANGE_TRIGGER.ADDED_COLUMN,
|
|
60
71
|
});
|
|
72
|
+
|
|
61
73
|
return updatedTr;
|
|
62
74
|
};
|
|
63
75
|
};
|
|
@@ -164,6 +176,15 @@ export const insertRow =
|
|
|
164
176
|
tr.setSelection(selection.map(tr.doc, tr.mapping));
|
|
165
177
|
}
|
|
166
178
|
|
|
179
|
+
if (getBooleanFF('platform.editor.table.analytics-plugin-moved-event')) {
|
|
180
|
+
updateRowOrColumnMovedTransform(
|
|
181
|
+
{
|
|
182
|
+
type: 'row',
|
|
183
|
+
},
|
|
184
|
+
'addRowOrColumn',
|
|
185
|
+
)(state, tr);
|
|
186
|
+
}
|
|
187
|
+
|
|
167
188
|
dispatch(tr);
|
|
168
189
|
}
|
|
169
190
|
return true;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// #region Imports
|
|
2
1
|
import type { CellAttributes } from '@atlaskit/adf-schema';
|
|
3
2
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
3
|
import {
|
|
@@ -13,7 +12,11 @@ import type {
|
|
|
13
12
|
Slice,
|
|
14
13
|
} from '@atlaskit/editor-prosemirror/model';
|
|
15
14
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
16
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
EditorState,
|
|
17
|
+
Selection,
|
|
18
|
+
Transaction,
|
|
19
|
+
} from '@atlaskit/editor-prosemirror/state';
|
|
17
20
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
18
21
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
19
22
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
@@ -72,11 +75,7 @@ export const setTableRef = (ref?: HTMLTableElement) =>
|
|
|
72
75
|
closestElement(tableRef, `.${ClassName.TABLE_NODE_WRAPPER}`) ||
|
|
73
76
|
undefined;
|
|
74
77
|
const layout = tableNode ? tableNode.attrs.layout : undefined;
|
|
75
|
-
const
|
|
76
|
-
state,
|
|
77
|
-
createColumnControlsDecoration(state.selection),
|
|
78
|
-
TableDecorations.COLUMN_CONTROLS_DECORATIONS,
|
|
79
|
-
);
|
|
78
|
+
const { isDragAndDropEnabled } = getPluginState(state);
|
|
80
79
|
|
|
81
80
|
return {
|
|
82
81
|
type: 'SET_TABLE_REF',
|
|
@@ -89,7 +88,14 @@ export const setTableRef = (ref?: HTMLTableElement) =>
|
|
|
89
88
|
isNumberColumnEnabled: checkIfNumberColumnEnabled(state.selection),
|
|
90
89
|
isHeaderRowEnabled: checkIfHeaderRowEnabled(state.selection),
|
|
91
90
|
isHeaderColumnEnabled: checkIfHeaderColumnEnabled(state.selection),
|
|
92
|
-
|
|
91
|
+
// decoration set is drawn by the decoration plugin, skip this for DnD as all controls are floating
|
|
92
|
+
decorationSet: !isDragAndDropEnabled
|
|
93
|
+
? updatePluginStateDecorations(
|
|
94
|
+
state,
|
|
95
|
+
createColumnControlsDecoration(state.selection),
|
|
96
|
+
TableDecorations.COLUMN_CONTROLS_DECORATIONS,
|
|
97
|
+
)
|
|
98
|
+
: undefined,
|
|
93
99
|
resizeHandleRowIndex: undefined,
|
|
94
100
|
resizeHandleColumnIndex: undefined,
|
|
95
101
|
},
|
|
@@ -232,6 +238,85 @@ export const transformSliceToRemoveColumnsWidths = (
|
|
|
232
238
|
});
|
|
233
239
|
};
|
|
234
240
|
|
|
241
|
+
export const countCellsInSlice = (
|
|
242
|
+
slice: Slice,
|
|
243
|
+
schema: Schema,
|
|
244
|
+
type?: 'row' | 'column',
|
|
245
|
+
) => {
|
|
246
|
+
const { tableHeader, tableCell } = schema.nodes;
|
|
247
|
+
let count = 0;
|
|
248
|
+
|
|
249
|
+
if (!type) {
|
|
250
|
+
return count;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
slice.content.descendants((maybeCell) => {
|
|
254
|
+
if (maybeCell.type === tableCell || maybeCell.type === tableHeader) {
|
|
255
|
+
count +=
|
|
256
|
+
type === 'row' ? maybeCell.attrs.colspan : maybeCell.attrs.rowspan;
|
|
257
|
+
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
return count;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export const getTableSelectionType = (selection: Selection) => {
|
|
266
|
+
if (selection instanceof CellSelection) {
|
|
267
|
+
return selection.isRowSelection()
|
|
268
|
+
? 'row'
|
|
269
|
+
: selection.isColSelection()
|
|
270
|
+
? 'column'
|
|
271
|
+
: undefined;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export const getTableElementMoveTypeBySlice = (
|
|
276
|
+
slice: Slice,
|
|
277
|
+
state: EditorState,
|
|
278
|
+
) => {
|
|
279
|
+
if (!slice.content.firstChild) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const { schema } = state;
|
|
284
|
+
|
|
285
|
+
// if the slice only contains one table row, assume it's a row
|
|
286
|
+
if (
|
|
287
|
+
slice.content.childCount === 1 &&
|
|
288
|
+
slice.content.firstChild.type === schema.nodes.tableRow
|
|
289
|
+
) {
|
|
290
|
+
return 'row';
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const table = findTable(state.tr.selection)!;
|
|
294
|
+
const map = TableMap.get(table.node);
|
|
295
|
+
const slicedMap = TableMap.get(slice.content.firstChild);
|
|
296
|
+
|
|
297
|
+
return map.width === slicedMap.width
|
|
298
|
+
? 'row'
|
|
299
|
+
: map.height === slicedMap.height
|
|
300
|
+
? 'column'
|
|
301
|
+
: undefined;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export const isInsideFirstCellOfRowOrColumn = (
|
|
305
|
+
selection: Selection,
|
|
306
|
+
type?: 'row' | 'column',
|
|
307
|
+
) => {
|
|
308
|
+
const table = findTable(selection);
|
|
309
|
+
|
|
310
|
+
if (!table || !type) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const map = TableMap.get(table.node!);
|
|
314
|
+
const cell = selectionCell(selection);
|
|
315
|
+
const index = map.map.findIndex((value) => value === cell!.pos! - 1);
|
|
316
|
+
|
|
317
|
+
return type === 'row' ? index % map.width === 0 : index < map.width;
|
|
318
|
+
};
|
|
319
|
+
|
|
235
320
|
export const deleteTable: Command = (state, dispatch) => {
|
|
236
321
|
if (dispatch) {
|
|
237
322
|
dispatch(removeTable(state.tr));
|
|
@@ -42,6 +42,8 @@ import { createTable } from '@atlaskit/editor-tables/utils';
|
|
|
42
42
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
43
43
|
|
|
44
44
|
import { pluginConfig } from './create-plugin-config';
|
|
45
|
+
import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analytics/plugin';
|
|
46
|
+
import { pluginKey as tableAnalyticsPluginKey } from './pm-plugins/analytics/plugin-key';
|
|
45
47
|
import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
|
|
46
48
|
import {
|
|
47
49
|
createPlugin as createDragAndDropPlugin,
|
|
@@ -56,10 +58,7 @@ import {
|
|
|
56
58
|
findStickyHeaderForTable,
|
|
57
59
|
pluginKey as stickyHeadersPluginKey,
|
|
58
60
|
} from './pm-plugins/sticky-headers';
|
|
59
|
-
import {
|
|
60
|
-
createPlugin as createTableAnalyticsPlugin,
|
|
61
|
-
pluginKey as tableAnalyticsPluginKey,
|
|
62
|
-
} from './pm-plugins/table-analytics';
|
|
61
|
+
import { createPlugin as createTableOverflowAnalyticsPlugin } from './pm-plugins/table-analytics';
|
|
63
62
|
import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
|
|
64
63
|
import {
|
|
65
64
|
createPlugin as createFlexiResizingPlugin,
|
|
@@ -295,17 +294,25 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
295
294
|
)
|
|
296
295
|
: undefined,
|
|
297
296
|
},
|
|
297
|
+
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
298
298
|
{
|
|
299
|
-
name: '
|
|
299
|
+
name: 'tableOverflowAnalyticsPlugin',
|
|
300
300
|
plugin: ({ dispatch, dispatchAnalyticsEvent }) =>
|
|
301
301
|
getBooleanFF('platform.editor.table.overflow-state-analytics')
|
|
302
|
-
?
|
|
302
|
+
? createTableOverflowAnalyticsPlugin(
|
|
303
303
|
dispatch,
|
|
304
304
|
dispatchAnalyticsEvent,
|
|
305
305
|
options?.tableResizingEnabled ?? false,
|
|
306
306
|
)
|
|
307
307
|
: undefined,
|
|
308
308
|
},
|
|
309
|
+
{
|
|
310
|
+
name: 'tableAnalyticsPlugin',
|
|
311
|
+
plugin: ({ dispatch, dispatchAnalyticsEvent }) =>
|
|
312
|
+
getBooleanFF('platform.editor.table.analytics-plugin-moved-event')
|
|
313
|
+
? createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent)
|
|
314
|
+
: undefined,
|
|
315
|
+
},
|
|
309
316
|
{
|
|
310
317
|
name: 'tableGetEditorViewReferencePlugin',
|
|
311
318
|
plugin: () => {
|