@atlaskit/editor-plugin-table 0.0.6 → 0.0.7

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/plugins/table/event-handlers.js +7 -6
  3. package/dist/cjs/plugins/table/nodeviews/tableCell.js +4 -4
  4. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  5. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  6. package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
  7. package/dist/cjs/version.json +1 -1
  8. package/dist/es2019/plugins/table/event-handlers.js +8 -7
  9. package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -4
  10. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  11. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  12. package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
  13. package/dist/es2019/version.json +1 -1
  14. package/dist/esm/plugins/table/event-handlers.js +8 -7
  15. package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -4
  16. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  17. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  18. package/dist/esm/plugins/table/utils/column-controls.js +1 -1
  19. package/dist/esm/version.json +1 -1
  20. package/package.json +4 -2
  21. package/src/__tests__/unit/analytics.ts +737 -0
  22. package/src/__tests__/unit/collab.ts +76 -0
  23. package/src/__tests__/unit/commands/sort.ts +230 -0
  24. package/src/__tests__/unit/copy-paste.ts +686 -0
  25. package/src/__tests__/unit/event-handlers/index.ts +106 -0
  26. package/src/__tests__/unit/event-handlers.ts +202 -0
  27. package/src/__tests__/unit/fix-tables.ts +156 -0
  28. package/src/__tests__/unit/floating-toolbar.ts +95 -0
  29. package/src/__tests__/unit/handlers.ts +81 -0
  30. package/src/__tests__/unit/hover-selection.ts +277 -0
  31. package/src/__tests__/unit/index-with-fake-timers.ts +106 -0
  32. package/src/__tests__/unit/index.ts +986 -0
  33. package/src/__tests__/unit/keymap.ts +602 -0
  34. package/src/__tests__/unit/layout.ts +196 -0
  35. package/src/__tests__/unit/nodeviews/cell.ts +167 -0
  36. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +33 -0
  37. package/src/__tests__/unit/sort-column.ts +512 -0
  38. package/src/__tests__/unit/transforms/delete-columns.ts +499 -0
  39. package/src/__tests__/unit/transforms/delete-rows.ts +557 -0
  40. package/src/__tests__/unit/transforms/merging.ts +374 -0
  41. package/src/__tests__/unit/ui/CornerControls.tsx +80 -0
  42. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +95 -0
  43. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +175 -0
  44. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +266 -0
  45. package/src/__tests__/unit/ui/RowControls.tsx +301 -0
  46. package/src/__tests__/unit/ui/TableFloatingControls.tsx +93 -0
  47. package/src/__tests__/unit/undo-redo.ts +202 -0
  48. package/src/__tests__/unit/utils/dom.ts +286 -0
  49. package/src/__tests__/unit/utils/nodes.ts +59 -0
  50. package/src/__tests__/unit/utils/row-controls.ts +176 -0
  51. package/src/__tests__/unit/utils/table.ts +93 -0
  52. package/src/__tests__/unit/utils.ts +652 -0
  53. package/src/plugins/table/event-handlers.ts +5 -6
  54. package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
  55. package/src/plugins/table/pm-plugins/table-resizing/utils/column-state.ts +1 -1
  56. package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +6 -2
  57. package/src/plugins/table/utils/column-controls.ts +1 -1
@@ -0,0 +1,76 @@
1
+ import {
2
+ doc,
3
+ p,
4
+ table,
5
+ tr,
6
+ td,
7
+ th,
8
+ DocBuilder,
9
+ } from '@atlaskit/editor-test-helpers/doc-builder';
10
+ import { removeColumnAt } from '@atlaskit/editor-tables/utils';
11
+ import { TablePluginState, PluginConfig } from '../../plugins/table/types';
12
+
13
+ import { setResizeHandlePos } from '../../plugins/table/pm-plugins/table-resizing/commands';
14
+ import { pluginKey as tablePluginKey } from '../../plugins/table/pm-plugins/plugin-key';
15
+ import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
16
+ import tablePlugin from '../../plugins/table-plugin';
17
+ const TABLE_LOCAL_ID = 'test-table-local-id';
18
+
19
+ describe('Tables with Collab editing', () => {
20
+ const createEditor = createEditorFactory<TablePluginState>();
21
+ const tableOptions = {
22
+ allowNumberColumn: true,
23
+ allowHeaderRow: true,
24
+ allowHeaderColumn: true,
25
+ permittedLayouts: 'all',
26
+ allowColumnResizing: true,
27
+ } as PluginConfig;
28
+
29
+ const editor = (doc: DocBuilder) => {
30
+ return createEditor({
31
+ doc,
32
+ editorProps: {
33
+ allowTables: false,
34
+ dangerouslyAppendPlugins: {
35
+ __plugins: [tablePlugin({ tableOptions })],
36
+ },
37
+ },
38
+ pluginKey: tablePluginKey,
39
+ });
40
+ };
41
+
42
+ it('applies colwidths to cells and sets autosize to false', () => {
43
+ const { editorView: view } = editor(
44
+ doc(
45
+ table({ localId: TABLE_LOCAL_ID })(
46
+ tr(th()(p('{<>}1')), th()(p('2')), th()(p('3'))),
47
+ tr(td()(p('4')), td()(p('5')), td()(p('6'))),
48
+ tr(td()(p('7')), td()(p('8')), td()(p('9'))),
49
+ ),
50
+ ),
51
+ );
52
+
53
+ // Trigger table resizing mouse down handlers.
54
+ setResizeHandlePos(2)(view.state, view.dispatch);
55
+ const mousedownEvent = new MouseEvent('mousedown', { clientX: 50 });
56
+ view.dom.dispatchEvent(mousedownEvent);
57
+
58
+ // Simulate collab change, delete col.
59
+ const documentChangeTr = removeColumnAt(1)(view.state.tr);
60
+ view.updateState(view.state.apply(documentChangeTr));
61
+
62
+ // Trigger table resizing finish handlers
63
+ const mouseupEvent = new MouseEvent('mouseup', { clientX: 150 });
64
+ window.dispatchEvent(mouseupEvent);
65
+
66
+ expect(view.state.doc).toEqualDocument(
67
+ doc(
68
+ table({ localId: TABLE_LOCAL_ID })(
69
+ tr(th()(p('1')), th()(p('3'))),
70
+ tr(td()(p('4')), td()(p('6'))),
71
+ tr(td()(p('7')), td()(p('9'))),
72
+ ),
73
+ ),
74
+ );
75
+ });
76
+ });
@@ -0,0 +1,230 @@
1
+ import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
2
+ import {
3
+ doc,
4
+ p,
5
+ table,
6
+ td,
7
+ th,
8
+ tr,
9
+ mention,
10
+ date,
11
+ a,
12
+ status,
13
+ } from '@atlaskit/editor-test-helpers/doc-builder';
14
+ import { EditorView } from 'prosemirror-view';
15
+ import { mentionResourceProvider } from '@atlaskit/util-data-test/mention-story-data';
16
+ import { sortByColumn } from '../../../plugins/table/commands/sort';
17
+ import { uuid } from '@atlaskit/adf-schema';
18
+ import { TableSortOrder as SortOrder } from '@atlaskit/adf-schema/steps';
19
+ import tablePlugin from '../../../plugins/table-plugin';
20
+
21
+ const TABLE_LOCAL_ID = 'test-table-local-id';
22
+
23
+ describe('Sort Table', () => {
24
+ beforeAll(() => {
25
+ uuid.setStatic(TABLE_LOCAL_ID);
26
+ });
27
+
28
+ afterAll(() => {
29
+ uuid.setStatic(false);
30
+ });
31
+
32
+ const createEditor = createEditorFactory();
33
+ it('should test a basic table with heading', () => {
34
+ const { editorView } = createEditor({
35
+ editorProps: {
36
+ dangerouslyAppendPlugins: {
37
+ __plugins: [tablePlugin({ tableOptions: { allowHeaderRow: true } })],
38
+ },
39
+ },
40
+ doc: doc(
41
+ table()(
42
+ tr(th({})(p('Number{<>}'))),
43
+ tr(td({})(p('10{<>}'))),
44
+ tr(td({})(p('0'))),
45
+ tr(td({})(p('5'))),
46
+ ),
47
+ ),
48
+ });
49
+ sortByColumn(0)(editorView.state, editorView.dispatch);
50
+
51
+ expect(editorView.state.doc).toEqualDocument(
52
+ doc(
53
+ table({ localId: TABLE_LOCAL_ID })(
54
+ tr(th({})(p('Number'))),
55
+ tr(td({})(p('10'))),
56
+ tr(td({})(p('5'))),
57
+ tr(td({})(p('0'))),
58
+ ),
59
+ ),
60
+ );
61
+ });
62
+
63
+ it('should test a basic table descending', () => {
64
+ const { editorView } = createEditor({
65
+ editorProps: {
66
+ dangerouslyAppendPlugins: {
67
+ __plugins: [tablePlugin({ tableOptions: { allowHeaderRow: true } })],
68
+ },
69
+ },
70
+ doc: doc(
71
+ table()(tr(td({})(p('2{<>}'))), tr(td({})(p('5'))), tr(td({})(p('4')))),
72
+ ),
73
+ });
74
+ sortByColumn(0)(editorView.state, editorView.dispatch);
75
+
76
+ expect(editorView.state.doc).toEqualDocument(
77
+ doc(
78
+ table({ localId: TABLE_LOCAL_ID })(
79
+ tr(td({})(p('5'))),
80
+ tr(td({})(p('4'))),
81
+ tr(td({})(p('2'))),
82
+ ),
83
+ ),
84
+ );
85
+ });
86
+
87
+ it('should test a basic table ascending', () => {
88
+ const { editorView } = createEditor({
89
+ editorProps: {
90
+ dangerouslyAppendPlugins: {
91
+ __plugins: [tablePlugin({ tableOptions: { allowHeaderRow: true } })],
92
+ },
93
+ },
94
+ doc: doc(
95
+ table()(tr(td({})(p('2{<>}'))), tr(td({})(p('5'))), tr(td({})(p('4')))),
96
+ ),
97
+ });
98
+ sortByColumn(0, SortOrder.ASC)(editorView.state, editorView.dispatch);
99
+
100
+ expect(editorView.state.doc).toEqualDocument(
101
+ doc(
102
+ table({ localId: TABLE_LOCAL_ID })(
103
+ tr(td({})(p('2'))),
104
+ tr(td({})(p('4'))),
105
+ tr(td({})(p('5'))),
106
+ ),
107
+ ),
108
+ );
109
+ });
110
+
111
+ describe('mixed content ordering', () => {
112
+ let editorView: EditorView;
113
+
114
+ beforeEach(() => {
115
+ ({ editorView } = createEditor({
116
+ editorProps: {
117
+ allowStatus: true,
118
+ allowDate: true,
119
+ dangerouslyAppendPlugins: {
120
+ __plugins: [
121
+ tablePlugin({ tableOptions: { allowHeaderRow: true } }),
122
+ ],
123
+ },
124
+ mentionProvider: Promise.resolve(mentionResourceProvider),
125
+ },
126
+ doc: doc(
127
+ table()(
128
+ tr(th({})(p('Mixed{<>}'))),
129
+ tr(td({})(p(a({ href: '' })('LinkB')))),
130
+ tr(td({})(p('a1'))),
131
+ tr(
132
+ td({})(
133
+ p(status({ text: 'statusB', color: '#FFF', localId: 'a' })),
134
+ ),
135
+ ),
136
+ tr(td({})(p('10'))),
137
+ tr(td({})(p('b1'))),
138
+ tr(td({})(p(mention({ id: 'a', text: 'MentionA' })()))),
139
+ tr(td({})(p('20'))),
140
+ tr(
141
+ td({})(p(date({ timestamp: new Date('2019-01-01').getTime() }))),
142
+ ),
143
+ tr(td({})(p(a({ href: '' })('LinkA')))),
144
+ tr(td({})(p(mention({ id: 'a', text: 'MentionB' })()))),
145
+ tr(
146
+ td({})(
147
+ p(status({ text: 'statusA', color: '#FFF', localId: 'a' })),
148
+ ),
149
+ ),
150
+ tr(
151
+ td({})(p(date({ timestamp: new Date('2020-01-01').getTime() }))),
152
+ ),
153
+ ),
154
+ ),
155
+ }));
156
+ });
157
+
158
+ it('should test a basic table ascending', () => {
159
+ sortByColumn(0, SortOrder.ASC)(editorView.state, editorView.dispatch);
160
+
161
+ expect(editorView.state.doc).toEqualDocument(
162
+ doc(
163
+ table({ localId: TABLE_LOCAL_ID })(
164
+ tr(th({})(p('Mixed{<>}'))),
165
+ tr(td({})(p('10'))),
166
+ tr(td({})(p('20'))),
167
+ tr(td({})(p('a1'))),
168
+ tr(td({})(p('b1'))),
169
+ tr(td({})(p(mention({ id: 'a', text: 'MentionA' })()))),
170
+ tr(td({})(p(mention({ id: 'a', text: 'MentionB' })()))),
171
+ tr(
172
+ td({})(p(date({ timestamp: new Date('2019-01-01').getTime() }))),
173
+ ),
174
+ tr(
175
+ td({})(p(date({ timestamp: new Date('2020-01-01').getTime() }))),
176
+ ),
177
+ tr(
178
+ td({})(
179
+ p(status({ text: 'statusA', color: '#FFF', localId: 'a' })),
180
+ ),
181
+ ),
182
+ tr(
183
+ td({})(
184
+ p(status({ text: 'statusB', color: '#FFF', localId: 'a' })),
185
+ ),
186
+ ),
187
+ tr(td({})(p(a({ href: '' })('LinkA')))),
188
+ tr(td({})(p(a({ href: '' })('LinkB')))),
189
+ ),
190
+ ),
191
+ );
192
+ });
193
+
194
+ it('should test a basic table descending', () => {
195
+ sortByColumn(0, SortOrder.DESC)(editorView.state, editorView.dispatch);
196
+
197
+ expect(editorView.state.doc).toEqualDocument(
198
+ doc(
199
+ table({ localId: TABLE_LOCAL_ID })(
200
+ tr(th({})(p('Mixed{<>}'))),
201
+ tr(td({})(p(a({ href: '' })('LinkB')))),
202
+ tr(td({})(p(a({ href: '' })('LinkA')))),
203
+ tr(
204
+ td({})(
205
+ p(status({ text: 'statusB', color: '#FFF', localId: 'a' })),
206
+ ),
207
+ ),
208
+ tr(
209
+ td({})(
210
+ p(status({ text: 'statusA', color: '#FFF', localId: 'a' })),
211
+ ),
212
+ ),
213
+ tr(
214
+ td({})(p(date({ timestamp: new Date('2020-01-01').getTime() }))),
215
+ ),
216
+ tr(
217
+ td({})(p(date({ timestamp: new Date('2019-01-01').getTime() }))),
218
+ ),
219
+ tr(td({})(p(mention({ id: 'a', text: 'MentionB' })()))),
220
+ tr(td({})(p(mention({ id: 'a', text: 'MentionA' })()))),
221
+ tr(td({})(p('b1'))),
222
+ tr(td({})(p('a1'))),
223
+ tr(td({})(p('20'))),
224
+ tr(td({})(p('10'))),
225
+ ),
226
+ ),
227
+ );
228
+ });
229
+ });
230
+ });