@atlaskit/editor-plugin-table 7.2.2 → 7.3.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 +14 -0
- package/dist/cjs/commands/column-resize.js +115 -45
- package/dist/cjs/commands/go-to-next-cell.js +7 -11
- package/dist/cjs/commands/misc.js +3 -2
- package/dist/cjs/commands/selection.js +3 -3
- package/dist/cjs/event-handlers.js +38 -25
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
- package/dist/cjs/pm-plugins/keymap.js +1 -0
- package/dist/cjs/pm-plugins/main.js +43 -9
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
- package/dist/cjs/reducer.js +5 -2
- package/dist/cjs/utils/drag-menu.js +37 -23
- package/dist/cjs/utils/merged-cells.js +66 -1
- package/dist/es2019/commands/column-resize.js +100 -35
- package/dist/es2019/commands/go-to-next-cell.js +7 -9
- package/dist/es2019/commands/misc.js +3 -2
- package/dist/es2019/commands/selection.js +5 -5
- package/dist/es2019/event-handlers.js +17 -3
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/es2019/pm-plugins/keymap.js +3 -2
- package/dist/es2019/pm-plugins/main.js +41 -5
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
- package/dist/es2019/reducer.js +5 -2
- package/dist/es2019/utils/drag-menu.js +38 -14
- package/dist/es2019/utils/merged-cells.js +73 -0
- package/dist/esm/commands/column-resize.js +105 -35
- package/dist/esm/commands/go-to-next-cell.js +7 -11
- package/dist/esm/commands/misc.js +3 -2
- package/dist/esm/commands/selection.js +5 -5
- package/dist/esm/event-handlers.js +38 -25
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
- package/dist/esm/pm-plugins/keymap.js +3 -2
- package/dist/esm/pm-plugins/main.js +38 -4
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
- package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
- package/dist/esm/reducer.js +5 -2
- package/dist/esm/utils/drag-menu.js +36 -22
- package/dist/esm/utils/merged-cells.js +65 -0
- package/dist/types/commands/column-resize.d.ts +2 -0
- package/dist/types/commands/misc.d.ts +1 -1
- package/dist/types/types.d.ts +16 -0
- package/dist/types/utils/drag-menu.d.ts +4 -1
- package/dist/types/utils/merged-cells.d.ts +2 -0
- package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
- package/dist/types-ts4.5/commands/misc.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +16 -0
- package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
- package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
- package/package.json +10 -17
- package/src/commands/column-resize.ts +155 -40
- package/src/commands/go-to-next-cell.ts +6 -15
- package/src/commands/misc.ts +2 -0
- package/src/commands/selection.ts +5 -5
- package/src/event-handlers.ts +21 -4
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
- package/src/pm-plugins/keymap.ts +3 -0
- package/src/pm-plugins/main.ts +47 -2
- package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
- package/src/pm-plugins/table-resizing/plugin.ts +18 -1
- package/src/reducer.ts +5 -2
- package/src/types.ts +16 -0
- package/src/utils/drag-menu.ts +94 -20
- package/src/utils/merged-cells.ts +78 -0
- package/tsconfig.dev.json +0 -69
- package/tsconfig.json +2 -877
- package/examples/99-testing.tsx +0 -140
- package/examples/config.jsonc +0 -14
- package/src/__tests__/unit/analytics.ts +0 -888
- package/src/__tests__/unit/collab.ts +0 -93
- package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
- package/src/__tests__/unit/commands/insert.ts +0 -137
- package/src/__tests__/unit/commands/misc.ts +0 -185
- package/src/__tests__/unit/commands/sort.ts +0 -128
- package/src/__tests__/unit/commands.ts +0 -745
- package/src/__tests__/unit/copy-button.ts +0 -22
- package/src/__tests__/unit/copy-paste.ts +0 -677
- package/src/__tests__/unit/event-handlers/index.ts +0 -125
- package/src/__tests__/unit/event-handlers.ts +0 -296
- package/src/__tests__/unit/fix-tables.ts +0 -164
- package/src/__tests__/unit/get-toolbar-config.ts +0 -127
- package/src/__tests__/unit/handlers.ts +0 -98
- package/src/__tests__/unit/hover-selection.ts +0 -230
- package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
- package/src/__tests__/unit/index.ts +0 -912
- package/src/__tests__/unit/layout.ts +0 -146
- package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
- package/src/__tests__/unit/nodeviews/cell.ts +0 -132
- package/src/__tests__/unit/nodeviews/table.ts +0 -129
- package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
- package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
- package/src/__tests__/unit/pm-plugins/main.ts +0 -214
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
- package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
- package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
- package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
- package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
- package/src/__tests__/unit/sort-column.ts +0 -399
- package/src/__tests__/unit/toolbar.ts +0 -512
- package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
- package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
- package/src/__tests__/unit/transforms/merging.ts +0 -392
- package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
- package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
- package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
- package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
- package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
- package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
- package/src/__tests__/unit/ui/RowControls.tsx +0 -294
- package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
- package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
- package/src/__tests__/unit/undo-redo.ts +0 -220
- package/src/__tests__/unit/utils/analytics.ts +0 -98
- package/src/__tests__/unit/utils/collapse.ts +0 -57
- package/src/__tests__/unit/utils/column-controls.ts +0 -205
- package/src/__tests__/unit/utils/dom.ts +0 -180
- package/src/__tests__/unit/utils/merged-cells.ts +0 -156
- package/src/__tests__/unit/utils/nodes.ts +0 -79
- package/src/__tests__/unit/utils/row-controls.ts +0 -195
- package/src/__tests__/unit/utils/table.ts +0 -96
- package/src/__tests__/unit/utils.ts +0 -670
- package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
- package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-should-remove-the-table-column-on-click-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-visual-hints-should-be-added-to-the-table-column-on-hover-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-should-remove-the-table-row-on-click-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-visual-hints-should-be-added-to-the-table-row-on-hover-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/copy-button-ts-floating-toolbar-copy-button-table-target-node-displays-blue-border-when-copy-button-is-hovered-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-2-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-3-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +0 -3
- package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +0 -3
- package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
- package/src/__tests__/visual-regression/copy-button.ts +0 -181
- package/src/__tests__/visual-regression/index.ts +0 -62
- package/src/__tests__/visual-regression/sticky-header.ts +0 -61
|
@@ -1,507 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import { replaceRaf } from 'raf-stub';
|
|
3
|
-
|
|
4
|
-
import { uuid } from '@atlaskit/adf-schema';
|
|
5
|
-
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
6
|
-
import type { DocBuilder } from '@atlaskit/editor-common/types';
|
|
7
|
-
import {
|
|
8
|
-
NodeSelection,
|
|
9
|
-
TextSelection,
|
|
10
|
-
} from '@atlaskit/editor-prosemirror/state';
|
|
11
|
-
import { __serializeForClipboard } from '@atlaskit/editor-prosemirror/view';
|
|
12
|
-
import { CellSelection } from '@atlaskit/editor-tables';
|
|
13
|
-
import { selectTable } from '@atlaskit/editor-tables/utils';
|
|
14
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
15
|
-
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
16
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
17
|
-
import dispatchPasteEvent from '@atlaskit/editor-test-helpers/dispatch-paste-event';
|
|
18
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
19
|
-
import {
|
|
20
|
-
doc,
|
|
21
|
-
expand,
|
|
22
|
-
layoutColumn,
|
|
23
|
-
layoutSection,
|
|
24
|
-
p,
|
|
25
|
-
table,
|
|
26
|
-
td,
|
|
27
|
-
th,
|
|
28
|
-
tr,
|
|
29
|
-
} from '@atlaskit/editor-test-helpers/doc-builder';
|
|
30
|
-
// eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
|
|
31
|
-
import { insertText } from '@atlaskit/editor-test-helpers/transactions';
|
|
32
|
-
|
|
33
|
-
import { handleCut } from '../../../event-handlers';
|
|
34
|
-
import { pluginKey as tablePluginKey } from '../../../pm-plugins/plugin-key';
|
|
35
|
-
import type { PluginConfig, TablePluginState } from '../../../types';
|
|
36
|
-
|
|
37
|
-
replaceRaf();
|
|
38
|
-
const requestAnimationFrame = window.requestAnimationFrame as any;
|
|
39
|
-
|
|
40
|
-
const mockUuidGenerated = 'a-mock-uuid';
|
|
41
|
-
const mockUuidGenerate = jest.fn().mockReturnValue(mockUuidGenerated);
|
|
42
|
-
|
|
43
|
-
jest.mock('@atlaskit/adf-schema', () => ({
|
|
44
|
-
...jest.requireActual<Object>('@atlaskit/adf-schema'),
|
|
45
|
-
uuid: {
|
|
46
|
-
generate: () => mockUuidGenerate(),
|
|
47
|
-
},
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
describe('table local id plugin', () => {
|
|
51
|
-
// Won't use `createProsemirrorEditorFactory` here, to also cover editorprops
|
|
52
|
-
const createEditor = createEditorFactory<TablePluginState>();
|
|
53
|
-
|
|
54
|
-
const editor = (
|
|
55
|
-
doc: DocBuilder,
|
|
56
|
-
options: {
|
|
57
|
-
skipRefs: boolean;
|
|
58
|
-
defaultValue: any;
|
|
59
|
-
} = {
|
|
60
|
-
skipRefs: false,
|
|
61
|
-
defaultValue: undefined,
|
|
62
|
-
},
|
|
63
|
-
) => {
|
|
64
|
-
const { skipRefs, defaultValue } = options;
|
|
65
|
-
const tableOptions = {
|
|
66
|
-
allowNumberColumn: true,
|
|
67
|
-
allowHeaderRow: true,
|
|
68
|
-
allowHeaderColumn: true,
|
|
69
|
-
allowBackgroundColor: true,
|
|
70
|
-
permittedLayouts: 'all',
|
|
71
|
-
} as PluginConfig;
|
|
72
|
-
return createEditor({
|
|
73
|
-
doc,
|
|
74
|
-
editorProps: {
|
|
75
|
-
allowExpand: true,
|
|
76
|
-
allowLayouts: true,
|
|
77
|
-
allowTables: tableOptions,
|
|
78
|
-
defaultValue,
|
|
79
|
-
},
|
|
80
|
-
pluginKey: tablePluginKey,
|
|
81
|
-
skipRefs,
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const localIdString = 'mochi-is-fluffy';
|
|
86
|
-
const localIdString2 = 'neko-is-hungry';
|
|
87
|
-
const flooFirst = 'floo-the-first';
|
|
88
|
-
const flooSecond = 'floo-the-second';
|
|
89
|
-
const flooThird = 'floo-the-third';
|
|
90
|
-
|
|
91
|
-
const generateTableWithLocalId = (localId: string) =>
|
|
92
|
-
table({ localId: localId })(
|
|
93
|
-
tr(th()(p('1')), th()(p('2')), th()(p('3'))),
|
|
94
|
-
tr(td()(p('4')), td()(p('5')), td()(p('6'))),
|
|
95
|
-
tr(td()(p('7')), td()(p('8')), td()(p('9'))),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
afterEach(() => {
|
|
99
|
-
jest.restoreAllMocks();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('Table localId duplication plugin', () => {
|
|
103
|
-
describe('table initialisation', () => {
|
|
104
|
-
it('should generate IDs on multiple tables without IDs', () => {
|
|
105
|
-
const spy = jest
|
|
106
|
-
.spyOn(uuid, 'generate')
|
|
107
|
-
.mockReturnValueOnce(flooFirst)
|
|
108
|
-
.mockReturnValueOnce(flooSecond);
|
|
109
|
-
/**
|
|
110
|
-
* We need to feed in a defaultValue here and skip the ref logic in
|
|
111
|
-
* createEditor as that setSelection fires off some transaction
|
|
112
|
-
* which inadvertently triggers our usual "a table is added" checks.
|
|
113
|
-
*
|
|
114
|
-
* We want to check that this flow can happen:
|
|
115
|
-
* 1. load document with pre-existing non-local-id table
|
|
116
|
-
* 2. immediately use it for charts (without adding a new table to
|
|
117
|
-
* trigger our "check all table IDs" logic in appendTransaction)
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
const tableAsDefaultValue = {
|
|
121
|
-
version: 1,
|
|
122
|
-
type: 'doc',
|
|
123
|
-
content: [
|
|
124
|
-
{
|
|
125
|
-
type: 'table',
|
|
126
|
-
attrs: {
|
|
127
|
-
isNumberColumnEnabled: false,
|
|
128
|
-
layout: 'default',
|
|
129
|
-
localId: undefined,
|
|
130
|
-
},
|
|
131
|
-
content: [
|
|
132
|
-
{
|
|
133
|
-
type: 'tableRow',
|
|
134
|
-
content: [
|
|
135
|
-
{
|
|
136
|
-
type: 'tableHeader',
|
|
137
|
-
content: [
|
|
138
|
-
{
|
|
139
|
-
type: 'paragraph',
|
|
140
|
-
content: [
|
|
141
|
-
{
|
|
142
|
-
type: 'text',
|
|
143
|
-
text: '1',
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
type: 'table',
|
|
155
|
-
attrs: {
|
|
156
|
-
isNumberColumnEnabled: false,
|
|
157
|
-
layout: 'default',
|
|
158
|
-
localId: undefined,
|
|
159
|
-
},
|
|
160
|
-
content: [
|
|
161
|
-
{
|
|
162
|
-
type: 'tableRow',
|
|
163
|
-
content: [
|
|
164
|
-
{
|
|
165
|
-
type: 'tableHeader',
|
|
166
|
-
content: [
|
|
167
|
-
{
|
|
168
|
-
type: 'paragraph',
|
|
169
|
-
content: [
|
|
170
|
-
{
|
|
171
|
-
type: 'text',
|
|
172
|
-
text: '1',
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
type: 'paragraph',
|
|
184
|
-
content: [],
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
};
|
|
188
|
-
const { editorView } = editor(doc(), {
|
|
189
|
-
skipRefs: true,
|
|
190
|
-
defaultValue: tableAsDefaultValue,
|
|
191
|
-
});
|
|
192
|
-
// Ensure we actually initialised with no ID
|
|
193
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
194
|
-
doc(
|
|
195
|
-
table({ localId: '' })(tr(th()(p('1')))),
|
|
196
|
-
table({ localId: '' })(tr(th()(p('1')))),
|
|
197
|
-
p(''),
|
|
198
|
-
),
|
|
199
|
-
);
|
|
200
|
-
expect(spy).toBeCalledTimes(0);
|
|
201
|
-
|
|
202
|
-
// Check we add IDs for existing tables
|
|
203
|
-
let { state } = editorView;
|
|
204
|
-
editorView.updateState(state);
|
|
205
|
-
requestAnimationFrame.step();
|
|
206
|
-
/**
|
|
207
|
-
* This one is really only needed if we use the "remove the
|
|
208
|
-
* `checkIsAddingTable` solution". But who doesn't want to feed the cats
|
|
209
|
-
*/
|
|
210
|
-
insertText(editorView, 'feed the cats', state.doc.nodeSize - 3);
|
|
211
|
-
|
|
212
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
213
|
-
doc(
|
|
214
|
-
table({ localId: flooFirst })(tr(th()(p('1')))),
|
|
215
|
-
table({ localId: flooSecond })(tr(th()(p('1')))),
|
|
216
|
-
p('feed the cats'),
|
|
217
|
-
),
|
|
218
|
-
);
|
|
219
|
-
expect(spy).toBeCalledTimes(2);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
describe('basic editing of a table', () => {
|
|
223
|
-
it('should NOT touch/overwrite localIds if inserting text inside a table', () => {
|
|
224
|
-
const { editorView, sel } = editor(
|
|
225
|
-
doc(
|
|
226
|
-
table({ localId: localIdString })(tr(th()(p('{<>}1')))),
|
|
227
|
-
table({ localId: localIdString2 })(tr(th()(p('2')))),
|
|
228
|
-
p(''),
|
|
229
|
-
),
|
|
230
|
-
);
|
|
231
|
-
let { state } = editorView;
|
|
232
|
-
editorView.updateState(state);
|
|
233
|
-
insertText(editorView, 'feed the cats', sel);
|
|
234
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
235
|
-
doc(
|
|
236
|
-
table({ localId: localIdString })(tr(th()(p('feed the cats1')))),
|
|
237
|
-
table({ localId: localIdString2 })(tr(th()(p('2')))),
|
|
238
|
-
p(''),
|
|
239
|
-
),
|
|
240
|
-
);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
describe('basic copy paste', () => {
|
|
244
|
-
it('generates a new ID when encountering a duplicate', () => {
|
|
245
|
-
const spy = jest.spyOn(uuid, 'generate').mockReturnValueOnce(flooFirst);
|
|
246
|
-
const {
|
|
247
|
-
editorView,
|
|
248
|
-
refs: { paragraphPos },
|
|
249
|
-
} = editor(
|
|
250
|
-
doc(
|
|
251
|
-
table({ localId: localIdString })(tr(th()(p('{<>}1')))),
|
|
252
|
-
p('{paragraphPos}'),
|
|
253
|
-
),
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
let { state } = editorView;
|
|
257
|
-
// select table
|
|
258
|
-
state = state.apply(selectTable(state.tr));
|
|
259
|
-
|
|
260
|
-
// copy table
|
|
261
|
-
const { dom, text } = __serializeForClipboard(
|
|
262
|
-
editorView,
|
|
263
|
-
state.selection.content(),
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
// move to paragraph
|
|
267
|
-
const $paraPos = state.doc.resolve(paragraphPos);
|
|
268
|
-
state = state.apply(
|
|
269
|
-
state.tr.setSelection(new TextSelection($paraPos, $paraPos)),
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
editorView.updateState(state);
|
|
273
|
-
|
|
274
|
-
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
275
|
-
|
|
276
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
277
|
-
doc(
|
|
278
|
-
table({ localId: localIdString })(tr(th()(p('1')))),
|
|
279
|
-
table({ localId: flooFirst })(tr(th()(p('1')))),
|
|
280
|
-
),
|
|
281
|
-
);
|
|
282
|
-
expect(spy).toBeCalledTimes(1);
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
describe('cut & multiple pastes', () => {
|
|
286
|
-
it('detects duplicates inside expand & tables', () => {
|
|
287
|
-
const spy = jest
|
|
288
|
-
.spyOn(uuid, 'generate')
|
|
289
|
-
.mockReturnValueOnce(flooSecond)
|
|
290
|
-
.mockReturnValueOnce(flooThird);
|
|
291
|
-
|
|
292
|
-
const {
|
|
293
|
-
editorView,
|
|
294
|
-
refs: { from, to, insideExpandPos, insideLayoutPos },
|
|
295
|
-
} = editor(
|
|
296
|
-
doc(
|
|
297
|
-
expand({ title: '' })(p('{insideExpandPos}')),
|
|
298
|
-
layoutSection(
|
|
299
|
-
layoutColumn({ width: 50 })(
|
|
300
|
-
table({ localId: flooFirst })(
|
|
301
|
-
tr(th()(p('{from}1')), th()(p('2')), th()(p('3'))),
|
|
302
|
-
tr(td()(p('4')), td()(p('5')), td()(p('6'))),
|
|
303
|
-
tr(td()(p('7')), td()(p('8')), td()(p('{to}9'))),
|
|
304
|
-
),
|
|
305
|
-
),
|
|
306
|
-
layoutColumn({ width: 50 })(p('{insideLayoutPos}')),
|
|
307
|
-
),
|
|
308
|
-
p(''),
|
|
309
|
-
),
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
let { state } = editorView;
|
|
313
|
-
// select table
|
|
314
|
-
const sel = new CellSelection(
|
|
315
|
-
state.doc.resolve(from - 2),
|
|
316
|
-
state.doc.resolve(to - 2),
|
|
317
|
-
);
|
|
318
|
-
editorView.dispatch(state.tr.setSelection(sel as any));
|
|
319
|
-
|
|
320
|
-
// "copy" table
|
|
321
|
-
const { dom, text } = __serializeForClipboard(
|
|
322
|
-
editorView,
|
|
323
|
-
sel.content(),
|
|
324
|
-
);
|
|
325
|
-
let state2 = editorView.state;
|
|
326
|
-
const insideLayout = state2.doc.resolve(insideLayoutPos);
|
|
327
|
-
// Move cursor inside layout
|
|
328
|
-
state2 = state2.apply(
|
|
329
|
-
state2.tr.setSelection(new TextSelection(insideLayout)),
|
|
330
|
-
);
|
|
331
|
-
editorView.updateState(state2);
|
|
332
|
-
|
|
333
|
-
// paste into layout, expect new ID
|
|
334
|
-
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
335
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
336
|
-
doc(
|
|
337
|
-
expand({ title: '' })(p('')),
|
|
338
|
-
layoutSection(
|
|
339
|
-
layoutColumn({ width: 50 })(generateTableWithLocalId(flooFirst)),
|
|
340
|
-
layoutColumn({ width: 50 })(generateTableWithLocalId(flooSecond)),
|
|
341
|
-
),
|
|
342
|
-
p(),
|
|
343
|
-
),
|
|
344
|
-
);
|
|
345
|
-
expect(spy).toBeCalledTimes(1);
|
|
346
|
-
|
|
347
|
-
let state3 = editorView.state;
|
|
348
|
-
const insideExpand = state3.doc.resolve(insideExpandPos);
|
|
349
|
-
// Move cursor inside layout
|
|
350
|
-
state3 = state3.apply(
|
|
351
|
-
state3.tr.setSelection(new TextSelection(insideExpand)),
|
|
352
|
-
);
|
|
353
|
-
editorView.updateState(state3);
|
|
354
|
-
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
355
|
-
|
|
356
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
357
|
-
doc(
|
|
358
|
-
expand({ title: '' })(generateTableWithLocalId(flooThird)),
|
|
359
|
-
layoutSection(
|
|
360
|
-
layoutColumn({ width: 50 })(generateTableWithLocalId(flooFirst)),
|
|
361
|
-
layoutColumn({ width: 50 })(generateTableWithLocalId(flooSecond)),
|
|
362
|
-
),
|
|
363
|
-
p(),
|
|
364
|
-
),
|
|
365
|
-
);
|
|
366
|
-
expect(spy).toBeCalledTimes(2);
|
|
367
|
-
});
|
|
368
|
-
it('generates a new ID when pasting a table with an existing ID', () => {
|
|
369
|
-
const spy = jest
|
|
370
|
-
.spyOn(uuid, 'generate')
|
|
371
|
-
.mockReturnValueOnce(flooFirst)
|
|
372
|
-
.mockReturnValueOnce(flooSecond);
|
|
373
|
-
|
|
374
|
-
const editorAnalyticsAPIFake: EditorAnalyticsAPI = {
|
|
375
|
-
attachAnalyticsEvent: jest.fn().mockReturnValue(() => jest.fn()),
|
|
376
|
-
fireAnalyticsEvent: jest.fn(),
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
const {
|
|
380
|
-
editorView,
|
|
381
|
-
refs: { from, to },
|
|
382
|
-
} = editor(
|
|
383
|
-
doc(
|
|
384
|
-
table({ localId: localIdString })(
|
|
385
|
-
tr(th()(p('{from}1')), th()(p('2')), th()(p('3'))),
|
|
386
|
-
tr(td()(p('4')), td()(p('5')), td()(p('6'))),
|
|
387
|
-
tr(td()(p('7')), td()(p('8')), td()(p('{to}9'))),
|
|
388
|
-
),
|
|
389
|
-
p('{paragraphPos}'),
|
|
390
|
-
),
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
let { state } = editorView;
|
|
394
|
-
// select table
|
|
395
|
-
const sel = new CellSelection(
|
|
396
|
-
state.doc.resolve(from - 2),
|
|
397
|
-
state.doc.resolve(to - 2),
|
|
398
|
-
);
|
|
399
|
-
editorView.dispatch(state.tr.setSelection(sel as any));
|
|
400
|
-
|
|
401
|
-
// "copy" table
|
|
402
|
-
const { dom, text } = __serializeForClipboard(
|
|
403
|
-
editorView,
|
|
404
|
-
sel.content(),
|
|
405
|
-
);
|
|
406
|
-
const oldState = editorView.state;
|
|
407
|
-
const newTr = handleCut(
|
|
408
|
-
oldState.tr,
|
|
409
|
-
oldState,
|
|
410
|
-
editorView.state,
|
|
411
|
-
editorAnalyticsAPIFake,
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
// Ensure table is "cut"/removed
|
|
415
|
-
expect(newTr.doc).toEqualDocument(doc(p('')));
|
|
416
|
-
editorView.dispatch(newTr);
|
|
417
|
-
|
|
418
|
-
expect(
|
|
419
|
-
editorAnalyticsAPIFake.attachAnalyticsEvent,
|
|
420
|
-
).toHaveBeenCalledWith({
|
|
421
|
-
action: 'cut',
|
|
422
|
-
actionSubject: 'table',
|
|
423
|
-
actionSubjectId: null,
|
|
424
|
-
attributes: {
|
|
425
|
-
horizontalCells: 3,
|
|
426
|
-
totalCells: 9,
|
|
427
|
-
totalColumnCount: 3,
|
|
428
|
-
totalRowCount: 3,
|
|
429
|
-
verticalCells: 3,
|
|
430
|
-
},
|
|
431
|
-
eventType: 'track',
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
// Paste it & ensure we retain the same ID
|
|
435
|
-
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
436
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
437
|
-
doc(generateTableWithLocalId(localIdString)),
|
|
438
|
-
);
|
|
439
|
-
|
|
440
|
-
/** Paste twice, observe for two new generated IDs */
|
|
441
|
-
let state2 = editorView.state;
|
|
442
|
-
const endOfDoc2 = state2.doc.resolve(state2.doc.nodeSize - 2);
|
|
443
|
-
// Move cursor to end of doc, to avoid pasting more cells into existing table
|
|
444
|
-
state2 = state2.apply(
|
|
445
|
-
state2.tr.setSelection(new TextSelection(endOfDoc2)),
|
|
446
|
-
);
|
|
447
|
-
editorView.updateState(state2);
|
|
448
|
-
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
449
|
-
|
|
450
|
-
// Second paste
|
|
451
|
-
let state3 = editorView.state;
|
|
452
|
-
const endOfDoc3 = state3.doc.resolve(state3.doc.nodeSize - 2);
|
|
453
|
-
// Move cursor to end of doc, to avoid pasting more cells into existing table
|
|
454
|
-
state3 = state3.apply(
|
|
455
|
-
state3.tr.setSelection(new TextSelection(endOfDoc3)),
|
|
456
|
-
);
|
|
457
|
-
editorView.updateState(state3);
|
|
458
|
-
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
459
|
-
|
|
460
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
461
|
-
doc(
|
|
462
|
-
generateTableWithLocalId(localIdString),
|
|
463
|
-
generateTableWithLocalId(flooFirst),
|
|
464
|
-
generateTableWithLocalId(flooSecond),
|
|
465
|
-
),
|
|
466
|
-
);
|
|
467
|
-
expect(spy).toBeCalledTimes(2);
|
|
468
|
-
});
|
|
469
|
-
it('_retains_ IDs when pasting the same table IDs over existing IDs', () => {
|
|
470
|
-
const spy = jest
|
|
471
|
-
.spyOn(uuid, 'generate')
|
|
472
|
-
.mockReturnValueOnce(flooFirst)
|
|
473
|
-
.mockReturnValueOnce(flooSecond);
|
|
474
|
-
|
|
475
|
-
const localIdString = 'mochi-is-fluffy';
|
|
476
|
-
const { editorView } = editor(
|
|
477
|
-
doc(
|
|
478
|
-
table({ localId: localIdString })(
|
|
479
|
-
tr(th()(p('1')), th()(p('2')), th()(p('3'))),
|
|
480
|
-
tr(td()(p('4')), td()(p('5')), td()(p('6'))),
|
|
481
|
-
tr(td()(p('7')), td()(p('8')), td()(p('9'))),
|
|
482
|
-
),
|
|
483
|
-
p(''),
|
|
484
|
-
),
|
|
485
|
-
);
|
|
486
|
-
|
|
487
|
-
let { state } = editorView;
|
|
488
|
-
// select doc
|
|
489
|
-
const sel = NodeSelection.create(state.doc, 0);
|
|
490
|
-
editorView.dispatch(state.tr.setSelection(sel));
|
|
491
|
-
|
|
492
|
-
// "copy" entire doc
|
|
493
|
-
const { dom, text } = __serializeForClipboard(
|
|
494
|
-
editorView,
|
|
495
|
-
sel.content(),
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
// Paste it & ensure we retain the same ID
|
|
499
|
-
dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
|
|
500
|
-
expect(editorView.state.doc).toEqualDocument(
|
|
501
|
-
doc(generateTableWithLocalId(localIdString), p('')),
|
|
502
|
-
);
|
|
503
|
-
expect(spy).not.toBeCalled();
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
});
|
|
507
|
-
});
|