@atlaskit/editor-plugin-table 2.0.1 → 2.1.1

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.
@@ -7,11 +7,9 @@ import {
7
7
  doc,
8
8
  p,
9
9
  table,
10
- h1,
11
10
  tr,
12
11
  td,
13
12
  th,
14
- strong,
15
13
  DocBuilder,
16
14
  } from '@atlaskit/editor-test-helpers/doc-builder';
17
15
  import {
@@ -20,8 +18,6 @@ import {
20
18
  } from '../../plugins/table/types';
21
19
  import { uuid } from '@atlaskit/adf-schema';
22
20
  import { TableSortOrder as SortOrder } from '@atlaskit/adf-schema/steps';
23
- import textFormattingPlugin from '@atlaskit/editor-core/src/plugins/text-formatting';
24
- import blockTypePlugin from '@atlaskit/editor-core/src/plugins/block-type';
25
21
  import { sortByColumn } from '../../plugins/table/commands';
26
22
  import { pluginKey as tablePluginKey } from '../../plugins/table/pm-plugins/plugin-key';
27
23
  import tablePlugin from '../../plugins/table-plugin';
@@ -56,9 +52,7 @@ describe('table plugin', () => {
56
52
  .add([analyticsPlugin, {}])
57
53
  .add(contentInsertionPlugin)
58
54
  .add(widthPlugin)
59
- .add([tablePlugin, { tableOptions }])
60
- .add(textFormattingPlugin)
61
- .add(blockTypePlugin);
55
+ .add([tablePlugin, { tableOptions }]);
62
56
 
63
57
  const editor = (doc: DocBuilder) => {
64
58
  return createEditor<TablePluginState, PluginKey>({
@@ -75,11 +69,11 @@ describe('table plugin', () => {
75
69
  doc(
76
70
  table({ isNumberColumnEnabled: false, layout: 'default' })(
77
71
  tr(
78
- th({})(p(strong('1'))),
79
- th({})(p(strong('2'))),
80
- th({})(p(strong('3'))),
81
- th({})(p(strong('4'))),
82
- th({})(p(strong('5'))),
72
+ th({})(p('1')),
73
+ th({})(p('2')),
74
+ th({})(p('3')),
75
+ th({})(p('4')),
76
+ th({})(p('5')),
83
77
  ),
84
78
  tr(
85
79
  td({})(p('c')),
@@ -139,11 +133,11 @@ describe('table plugin', () => {
139
133
  localId: TABLE_LOCAL_ID,
140
134
  })(
141
135
  tr(
142
- th({})(p(strong('1'))),
143
- th({})(p(strong('2'))),
144
- th({})(p(strong('3'))),
145
- th({})(p(strong('4'))),
146
- th({})(p(strong('5'))),
136
+ th({})(p('1')),
137
+ th({})(p('2')),
138
+ th({})(p('3')),
139
+ th({})(p('4')),
140
+ th({})(p('5')),
147
141
  ),
148
142
  tr(
149
143
  td({})(p('1')),
@@ -196,11 +190,11 @@ describe('table plugin', () => {
196
190
  doc(
197
191
  table({ isNumberColumnEnabled: false, layout: 'default' })(
198
192
  tr(
199
- th({})(p(strong('1'))),
200
- th({})(p(strong('2'))),
201
- th({})(p(strong('3'))),
202
- th({})(p(strong('4'))),
203
- th({})(p(strong('5'))),
193
+ th({})(p('1')),
194
+ th({})(p('2')),
195
+ th({})(p('3')),
196
+ th({})(p('4')),
197
+ th({})(p('5')),
204
198
  ),
205
199
  tr(
206
200
  td({})(p('c')),
@@ -260,11 +254,11 @@ describe('table plugin', () => {
260
254
  localId: TABLE_LOCAL_ID,
261
255
  })(
262
256
  tr(
263
- th({})(p(strong('1'))),
264
- th({})(p(strong('2'))),
265
- th({})(p(strong('3'))),
266
- th({})(p(strong('4'))),
267
- th({})(p(strong('5'))),
257
+ th({})(p('1')),
258
+ th({})(p('2')),
259
+ th({})(p('3')),
260
+ th({})(p('4')),
261
+ th({})(p('5')),
268
262
  ),
269
263
  tr(
270
264
  td({})(p('c')),
@@ -312,127 +306,6 @@ describe('table plugin', () => {
312
306
  ),
313
307
  );
314
308
  });
315
- it('sorts the given column with header text in ascending order', () => {
316
- const { editorView } = editor(
317
- doc(
318
- table({ isNumberColumnEnabled: false, layout: 'default' })(
319
- tr(
320
- th({})(h1(strong('asdasdasd'))),
321
- th({})(p(strong('asdasd'))),
322
- th({})(p(strong('sdfsdf'))),
323
- th({})(p('sdfsdfsdf')),
324
- th({})(p(strong('asdasda'))),
325
- ),
326
- tr(
327
- td({})(h1(strong('c'))),
328
- td({})(p('cda')),
329
- td({})(p()),
330
- td({})(p('cz')),
331
- td({})(p()),
332
- ),
333
- tr(
334
- td({})(h1(strong('b'))),
335
- td({})(p()),
336
- td({})(p('dfsf')),
337
- td({})(p()),
338
- td({})(p('cvsd')),
339
- ),
340
- tr(
341
- td({})(p(strong('a'))),
342
- td({})(p('zc')),
343
- td({})(p()),
344
- td({})(p()),
345
- td({})(p('fsdf')),
346
- ),
347
- tr(
348
- td({})(p(strong('2'))),
349
- td({})(p()),
350
- td({})(p()),
351
- td({})(p()),
352
- td({})(p()),
353
- ),
354
- tr(
355
- td({})(p(strong('1'))),
356
- td({})(p()),
357
- td({})(p('cxzcz')),
358
- td({})(p()),
359
- td({})(p()),
360
- ),
361
- tr(
362
- td({})(p()),
363
- td({})(p()),
364
- td({})(p()),
365
- td({})(p('sdfs')),
366
- td({})(p()),
367
- ),
368
- ),
369
- ),
370
- );
371
-
372
- const sortByColumnCommand = sortByColumn(0, SortOrder.ASC);
373
-
374
- sortByColumnCommand(editorView.state, editorView.dispatch);
375
-
376
- expect(editorView.state.doc).toEqualDocument(
377
- doc(
378
- table({
379
- isNumberColumnEnabled: false,
380
- layout: 'default',
381
- localId: TABLE_LOCAL_ID,
382
- })(
383
- tr(
384
- th({})(h1(strong('asdasdasd'))),
385
- th({})(p(strong('asdasd'))),
386
- th({})(p(strong('sdfsdf'))),
387
- th({})(p('sdfsdfsdf')),
388
- th({})(p(strong('asdasda'))),
389
- ),
390
- tr(
391
- td({})(p(strong('1'))),
392
- td({})(p()),
393
- td({})(p('cxzcz')),
394
- td({})(p()),
395
- td({})(p()),
396
- ),
397
- tr(
398
- td({})(p(strong('2'))),
399
- td({})(p()),
400
- td({})(p()),
401
- td({})(p()),
402
- td({})(p()),
403
- ),
404
- tr(
405
- td({})(p(strong('a'))),
406
- td({})(p('zc')),
407
- td({})(p()),
408
- td({})(p()),
409
- td({})(p('fsdf')),
410
- ),
411
- tr(
412
- td({})(h1(strong('b'))),
413
- td({})(p()),
414
- td({})(p('dfsf')),
415
- td({})(p()),
416
- td({})(p('cvsd')),
417
- ),
418
- tr(
419
- td({})(h1(strong('c'))),
420
- td({})(p('cda')),
421
- td({})(p()),
422
- td({})(p('cz')),
423
- td({})(p()),
424
- ),
425
- tr(
426
- td({})(p()),
427
- td({})(p()),
428
- td({})(p()),
429
- td({})(p('sdfs')),
430
- td({})(p()),
431
- ),
432
- ),
433
- ),
434
- );
435
- });
436
309
 
437
310
  describe('case sensitivity', () => {
438
311
  describe('ascending order', () => {
@@ -12,22 +12,17 @@ import {
12
12
  } from '@atlaskit/editor-test-helpers/doc-builder';
13
13
 
14
14
  import tablePlugin from '../../../plugins/table';
15
- import expandPlugin from '@atlaskit/editor-core/src/plugins/expand';
16
15
  import { widthPlugin } from '@atlaskit/editor-plugin-width';
17
16
 
18
- import {
19
- isTableCollapsible,
20
- collapseSelectedTable,
21
- } from '../../../plugins/table/utils/collapse';
17
+ import { isTableCollapsible } from '../../../plugins/table/utils/collapse';
22
18
  import featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
23
19
  import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
24
20
  import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
25
- import { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
26
21
 
27
22
  describe('collapse', () => {
28
23
  const createEditor = createProsemirrorEditorFactory();
29
24
 
30
- const editor = (doc: DocBuilder, expandInPlugins?: boolean) => {
25
+ const editor = (doc: DocBuilder) => {
31
26
  const preset = new Preset<LightEditorPlugin>()
32
27
  .add([featureFlagsPlugin, {}])
33
28
  .add([analyticsPlugin, {}])
@@ -35,11 +30,7 @@ describe('collapse', () => {
35
30
  .add(widthPlugin)
36
31
  .add(tablePlugin);
37
32
 
38
- const finalPreset = expandInPlugins
39
- ? preset.add(decorationsPlugin).add(expandPlugin)
40
- : preset;
41
-
42
- return createEditor({ doc, preset: finalPreset });
33
+ return createEditor({ doc, preset });
43
34
  };
44
35
 
45
36
  describe('isTableCollapsible', () => {
@@ -55,32 +46,5 @@ describe('collapse', () => {
55
46
  expect(newTr.steps.length).toEqual(0);
56
47
  expect(isTableCollapsibleRes.tableIsCollapsible).toEqual(false);
57
48
  });
58
-
59
- it('should allow collapsing a table when expands are in schema', () => {
60
- const editorData = editor(doc(table()(tr(tdEmpty, tdEmpty))), true);
61
- const editorView = editorData.editorView;
62
- const newTr = editorView.state.tr;
63
-
64
- expect(newTr.steps.length).toEqual(0);
65
-
66
- const isTableCollapsibleRes = isTableCollapsible(newTr);
67
-
68
- expect(newTr.steps.length).toEqual(0);
69
- expect(isTableCollapsibleRes.tableIsCollapsible).toEqual(true);
70
- });
71
- });
72
-
73
- describe('collapseSelectedTable', () => {
74
- it('should add steps to tr when called', () => {
75
- const editorData = editor(doc(table()(tr(tdEmpty, tdEmpty))), true);
76
- const editorView = editorData.editorView;
77
- const newTr = editorView.state.tr;
78
-
79
- expect(newTr.steps.length).toEqual(0);
80
-
81
- const collapseTr = collapseSelectedTable(newTr);
82
- expect(collapseTr).toBeDefined();
83
- expect(collapseTr!.steps.length).toEqual(1);
84
- });
85
49
  });
86
50
  });
package/.eslintrc.js DELETED
@@ -1,37 +0,0 @@
1
- module.exports = {
2
- rules: {
3
- // Ensure the table plugin is not coupled to editor-core and avoid circular dependencies
4
- 'no-restricted-imports': [
5
- 'error',
6
- {
7
- patterns: [
8
- {
9
- group: ['@atlaskit/editor-core/*', '@atlaskit/editor-core'],
10
- message:
11
- 'Importing editor-core is not allowed in editor-plugin-table. Consider using editor-common instead.',
12
- },
13
- ],
14
- },
15
- ],
16
- 'react/no-danger': 'error',
17
- },
18
- // Disable restricted import for tests
19
- overrides: [
20
- {
21
- files: ['**/__tests__/**/*.{js,ts,tsx}', 'examples/**/*.{js,ts,tsx}'],
22
- rules: {
23
- 'no-restricted-imports': [
24
- 'off',
25
- {
26
- patterns: [
27
- {
28
- group: ['@atlaskit/editor-core/*', '@atlaskit/editor-core'],
29
- },
30
- ],
31
- },
32
- ],
33
- 'react/no-danger': 'off',
34
- },
35
- },
36
- ],
37
- };
@@ -1,110 +0,0 @@
1
- import {
2
- doc,
3
- DocBuilder,
4
- p,
5
- table,
6
- tdCursor,
7
- tdEmpty,
8
- tr,
9
- } from '@atlaskit/editor-test-helpers/doc-builder';
10
- import {
11
- createProsemirrorEditorFactory,
12
- LightEditorPlugin,
13
- Preset,
14
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
15
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
16
- import type {
17
- FloatingToolbarButton,
18
- FloatingToolbarItem,
19
- GetEditorFeatureFlags,
20
- } from '@atlaskit/editor-common/types';
21
- import dataConsumerPlugin from '@atlaskit/editor-core/src/plugins/data-consumer';
22
- import extensionPlugin from '@atlaskit/editor-core/src/plugins/extension';
23
- import tablePlugin from '../../plugins/table';
24
- import { setEditorFocus, setTableRef } from '../../plugins/table/commands';
25
- import { getToolbarConfig } from '../../plugins/table/toolbar';
26
- import featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
27
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
28
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
29
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
30
- import { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
31
-
32
- const formatMessage: (t: { id: string }) => string = (message) =>
33
- `${message.id}`;
34
-
35
- describe('color picker', () => {
36
- /**
37
- * Use `createEditorFactory` here to enable referentiality as
38
- * `createProsemirrorEditorFactory` has some issues with correctly mimicking
39
- * old state for the unique localId plugin
40
- */
41
- const createEditorFn = createProsemirrorEditorFactory();
42
- const createEditor = (doc: DocBuilder) => {
43
- const output = createEditorFn({
44
- doc,
45
-
46
- attachTo: document.body,
47
- preset: new Preset<LightEditorPlugin>()
48
- .add([featureFlagsPlugin, {}])
49
- .add([analyticsPlugin, {}])
50
- .add(decorationsPlugin)
51
- .add(contentInsertionPlugin)
52
- .add(widthPlugin)
53
- .add(dataConsumerPlugin)
54
- .add(extensionPlugin)
55
- .add(tablePlugin),
56
- });
57
-
58
- // Prep the table plugin state a little
59
- const { editorView } = output;
60
- const { dispatch } = editorView;
61
- const tableRef = document.querySelector(
62
- '.ProseMirror table',
63
- ) as HTMLTableElement;
64
- setEditorFocus(true)(output.editorView.state, dispatch);
65
- setTableRef(tableRef)(output.editorView.state, dispatch);
66
-
67
- return output;
68
- };
69
-
70
- it('should return a corect color picker option if allowBackgroundColor enabled', async () => {
71
- const { editorView } = createEditor(
72
- doc(p('text'), table()(tr(tdCursor, tdEmpty))),
73
- );
74
- const getEditorContainerWidth = () => ({ width: 500 });
75
- const editorAnalyticsAPIFake: EditorAnalyticsAPI = {
76
- attachAnalyticsEvent: jest.fn().mockReturnValue(() => jest.fn()),
77
- };
78
-
79
- // Enable tableCellOptionsInFloatingToolbar
80
- const getEditorFeatureFlags: GetEditorFeatureFlags = jest
81
- .fn()
82
- .mockReturnValue({
83
- tableCellOptionsInFloatingToolbar: true,
84
- });
85
-
86
- // Enable allowBackgroundColor feature flag
87
- const { state } = editorView;
88
- (state as any).tablePlugin$.pluginConfig.allowBackgroundColor = true;
89
-
90
- // Create the editor
91
- const config = getToolbarConfig(
92
- getEditorContainerWidth,
93
- editorAnalyticsAPIFake,
94
- getEditorFeatureFlags,
95
- () => editorView,
96
- )({})(state, { formatMessage } as any, {} as any)!;
97
-
98
- // Let's find the colorPicker from the option items list
99
- const items =
100
- typeof config.items === 'function'
101
- ? config.items(state.doc.firstChild!)
102
- : config.items;
103
-
104
- const option = items.find(
105
- (item: FloatingToolbarItem<any>) =>
106
- item.type === 'select' && item.id === 'editor.table.colorPicker',
107
- )! as FloatingToolbarButton<any>;
108
- expect(option).not.toBeUndefined();
109
- });
110
- });
@@ -1,95 +0,0 @@
1
- // TODO: still broken
2
- import { PluginConfig } from '../../plugins/table/types';
3
- import { setTextSelection } from '@atlaskit/editor-common/utils';
4
- import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
5
- import {
6
- doc,
7
- p,
8
- table,
9
- tr,
10
- td,
11
- th,
12
- DocBuilder,
13
- } from '@atlaskit/editor-test-helpers/doc-builder';
14
- import {
15
- FloatingToolbarPluginState,
16
- pluginKey as floatingToolbarPluginKey,
17
- } from '@atlaskit/editor-core/src/plugins/floating-toolbar';
18
- import { setEditorFocus } from '../../plugins/table/commands';
19
- import { EditorState } from 'prosemirror-state';
20
- import tablePlugin from '../../plugins/table-plugin';
21
-
22
- describe('table floating toolbar', () => {
23
- const createEditor = createEditorFactory();
24
-
25
- const editor = (doc: DocBuilder) => {
26
- const tableOptions = {
27
- allowNumberColumn: true,
28
- allowHeaderRow: true,
29
- allowHeaderColumn: true,
30
- permittedLayouts: 'all',
31
- } as PluginConfig;
32
-
33
- return createEditor({
34
- doc,
35
- editorProps: {
36
- dangerouslyAppendPlugins: {
37
- __plugins: [tablePlugin({ tableOptions })],
38
- },
39
- },
40
- });
41
- };
42
-
43
- describe('when selecting a cell', () => {
44
- it('should contain the floating toolbar info within the first dispatch', () => {
45
- const { editorView, onEditorViewStateUpdatedCallbacks } = editor(
46
- doc(
47
- p('te{<>}xt'),
48
- table()(
49
- tr(
50
- th({ colwidth: [100, 100] })(p('1')),
51
- th({ colwidth: [100, 100] })(p('2')),
52
- th({ colwidth: [480] })(p('3')),
53
- ),
54
- tr(
55
- td({ colwidth: [100, 100] })(p('4')),
56
- td({ colwidth: [100, 100] })(p('5')),
57
- td({ colwidth: [480] })(p('6')),
58
- ),
59
- ),
60
- ),
61
- );
62
-
63
- setEditorFocus(true)(editorView.state, editorView.dispatch);
64
- setTextSelection(editorView, 5);
65
-
66
- const pluginStates: Array<{ config: any } | null | undefined> = [];
67
-
68
- const mock = jest.fn(
69
- ({ newEditorState }: { newEditorState: EditorState }) => {
70
- const { getConfigWithNodeInfo } = floatingToolbarPluginKey.getState(
71
- newEditorState,
72
- ) as FloatingToolbarPluginState;
73
- pluginStates.push(getConfigWithNodeInfo(editorView.state));
74
- },
75
- );
76
-
77
- onEditorViewStateUpdatedCallbacks.push({
78
- pluginName: 'listener',
79
- callback: mock,
80
- });
81
- setTextSelection(editorView, 9);
82
-
83
- expect(pluginStates).toHaveLength(2);
84
- // Inner dispatch for #findTable
85
- const firstCall = pluginStates[0];
86
- expect(firstCall).toBeTruthy();
87
- expect(firstCall!.config).toBeTruthy();
88
-
89
- // Outer dispatch for selection change
90
- const secondCall = pluginStates[1];
91
- expect(secondCall).toBeTruthy();
92
- expect(secondCall!.config).toBeTruthy();
93
- });
94
- });
95
- });