@atlaskit/editor-plugin-table 4.1.0 → 4.2.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/table/commands/delete.js +18 -0
  3. package/dist/cjs/plugins/table/commands-with-analytics.js +2 -7
  4. package/dist/cjs/plugins/table/event-handlers.js +2 -2
  5. package/dist/cjs/plugins/table/nodeviews/TableContainer.js +27 -9
  6. package/dist/cjs/plugins/table/pm-plugins/main.js +1 -1
  7. package/dist/cjs/plugins/table/transforms/column-width.js +110 -5
  8. package/dist/cjs/plugins/table/transforms/delete-columns.js +16 -6
  9. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  10. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  11. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  12. package/dist/es2019/plugins/table/commands/delete.js +10 -0
  13. package/dist/es2019/plugins/table/commands-with-analytics.js +3 -8
  14. package/dist/es2019/plugins/table/event-handlers.js +2 -2
  15. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +27 -9
  16. package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
  17. package/dist/es2019/plugins/table/transforms/column-width.js +105 -5
  18. package/dist/es2019/plugins/table/transforms/delete-columns.js +16 -5
  19. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  20. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  21. package/dist/es2019/plugins/table/ui/common-styles.js +0 -1
  22. package/dist/esm/plugins/table/commands/delete.js +12 -0
  23. package/dist/esm/plugins/table/commands-with-analytics.js +3 -8
  24. package/dist/esm/plugins/table/event-handlers.js +2 -2
  25. package/dist/esm/plugins/table/nodeviews/TableContainer.js +27 -9
  26. package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
  27. package/dist/esm/plugins/table/transforms/column-width.js +111 -5
  28. package/dist/esm/plugins/table/transforms/delete-columns.js +16 -6
  29. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  30. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  31. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  32. package/dist/types/plugins/table/commands/delete.d.ts +3 -0
  33. package/dist/types/plugins/table/event-handlers.d.ts +1 -1
  34. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +3 -3
  35. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  36. package/dist/types/plugins/table/transforms/column-width.d.ts +25 -6
  37. package/dist/types/plugins/table/transforms/delete-columns.d.ts +2 -1
  38. package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +4 -4
  39. package/dist/types-ts4.5/plugins/table/commands/delete.d.ts +3 -0
  40. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -1
  41. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +3 -3
  42. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  43. package/dist/types-ts4.5/plugins/table/transforms/column-width.d.ts +25 -6
  44. package/dist/types-ts4.5/plugins/table/transforms/delete-columns.d.ts +2 -1
  45. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +4 -4
  46. package/package.json +8 -2
  47. package/src/__tests__/unit/commands.ts +1 -0
  48. package/src/__tests__/unit/transforms/delete-columns.ts +406 -105
  49. package/src/__tests__/unit/undo-redo.ts +1 -1
  50. package/src/plugins/table/commands/delete.ts +20 -0
  51. package/src/plugins/table/commands-with-analytics.ts +3 -10
  52. package/src/plugins/table/event-handlers.ts +6 -1
  53. package/src/plugins/table/nodeviews/TableContainer.tsx +189 -159
  54. package/src/plugins/table/pm-plugins/main.ts +7 -1
  55. package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +1 -1
  56. package/src/plugins/table/transforms/column-width.ts +155 -15
  57. package/src/plugins/table/transforms/delete-columns.ts +23 -6
  58. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +1 -1
  59. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +7 -6
  60. package/src/plugins/table/ui/common-styles.ts +0 -1
@@ -4,12 +4,15 @@ import { TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics
4
4
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
5
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
6
6
  import { Selection } from '@atlaskit/editor-prosemirror/state';
7
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
8
  import type { Rect } from '@atlaskit/editor-tables/table-map';
8
9
  import { TableMap } from '@atlaskit/editor-tables/table-map';
9
10
  import { findTable } from '@atlaskit/editor-tables/utils';
11
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
10
12
 
11
13
  import { META_KEYS } from '../pm-plugins/table-analytics';
12
14
 
15
+ import { rescaleColumns } from './column-width';
13
16
  import { splitCellsInColumns } from './split';
14
17
 
15
18
  const deleteColumnsCustomStep =
@@ -247,13 +250,27 @@ function fixRowSpans(table: PMNode): PMNode | null {
247
250
  }
248
251
 
249
252
  export const deleteColumns =
250
- (rect: Rect, allowAddColumnCustomStep = false) =>
251
- (tr: Transaction): Transaction => {
252
- tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
253
+ (rect: Rect, allowCustomStep: boolean, view?: EditorView) =>
254
+ (tr: Transaction) => {
255
+ let updatedTr = tr;
256
+ updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
253
257
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.DELETED_COLUMN,
254
258
  });
255
- if (allowAddColumnCustomStep) {
256
- return deleteColumnsCustomStep(rect)(tr);
259
+
260
+ if (allowCustomStep) {
261
+ updatedTr = deleteColumnsCustomStep(rect)(updatedTr);
262
+ } else {
263
+ updatedTr = deleteColumnsLegacy(rect)(updatedTr);
264
+ }
265
+ const table = findTable(updatedTr.selection);
266
+ if (
267
+ getBooleanFF(
268
+ 'platform.editor.table-update-colwidths-after-column-is-deleted',
269
+ )
270
+ ) {
271
+ if (table) {
272
+ updatedTr = rescaleColumns()(table, view)(updatedTr);
273
+ }
257
274
  }
258
- return deleteColumnsLegacy(rect)(tr);
275
+ return updatedTr;
259
276
  };
@@ -434,7 +434,7 @@ export class ContextualMenu extends Component<
434
434
  deleteColumnsWithAnalytics(editorAnalyticsAPI)(
435
435
  INPUT_METHOD.CONTEXT_MENU,
436
436
  selectionRect,
437
- )(state, dispatch);
437
+ )(state, dispatch, editorView);
438
438
  this.toggleOpen();
439
439
  break;
440
440
  case 'delete_row':
@@ -1,4 +1,5 @@
1
- import React, { Component, SyntheticEvent } from 'react';
1
+ import type { SyntheticEvent } from 'react';
2
+ import React, { Component } from 'react';
2
3
 
3
4
  import { createPortal } from 'react-dom';
4
5
 
@@ -6,8 +7,8 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
7
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
7
8
  import { Popup } from '@atlaskit/editor-common/ui';
8
9
  import { closestElement } from '@atlaskit/editor-common/utils';
9
- import { Selection } from '@atlaskit/editor-prosemirror/state';
10
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
10
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
11
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
11
12
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
12
13
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
13
14
  import {
@@ -21,7 +22,7 @@ import {
21
22
  deleteRowsWithAnalytics,
22
23
  } from '../../commands-with-analytics';
23
24
  import { getPluginState as getTablePluginState } from '../../pm-plugins/plugin-factory';
24
- import { RowStickyState } from '../../pm-plugins/sticky-headers';
25
+ import type { RowStickyState } from '../../pm-plugins/sticky-headers';
25
26
  import { TableCssClassName as ClassName } from '../../types';
26
27
  import {
27
28
  getColumnDeleteButtonParams,
@@ -34,7 +35,7 @@ import tableMessages from '../messages';
34
35
 
35
36
  import DeleteButton from './DeleteButton';
36
37
  import getPopupOptions from './getPopUpOptions';
37
- import { CellSelectionType } from './types';
38
+ import type { CellSelectionType } from './types';
38
39
 
39
40
  export interface Props {
40
41
  editorView: EditorView;
@@ -278,7 +279,7 @@ class FloatingDeleteButton extends Component<Props, State> {
278
279
  deleteColumnsWithAnalytics(editorAnalyticsAPI)(
279
280
  INPUT_METHOD.BUTTON,
280
281
  rect,
281
- )(state, dispatch);
282
+ )(state, dispatch, this.props.editorView);
282
283
  return;
283
284
  }
284
285
  case 'row': {
@@ -249,7 +249,6 @@ const tableWrapperStyles = () => {
249
249
  position: relative;
250
250
 
251
251
  > table[data-number-column='true'] {
252
- margin-left: 1px;
253
252
  width: calc(100% - 1px);
254
253
  }
255
254
  }