@atlaskit/editor-plugin-table 4.1.1 → 4.2.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.
Files changed (199) hide show
  1. package/CHANGELOG.md +12 -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/pm-plugins/main.js +1 -1
  6. package/dist/cjs/plugins/table/transforms/column-width.js +112 -7
  7. package/dist/cjs/plugins/table/transforms/delete-columns.js +16 -6
  8. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  9. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  10. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  11. package/dist/es2019/plugins/table/commands/delete.js +10 -0
  12. package/dist/es2019/plugins/table/commands-with-analytics.js +3 -8
  13. package/dist/es2019/plugins/table/event-handlers.js +2 -2
  14. package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
  15. package/dist/es2019/plugins/table/transforms/column-width.js +107 -7
  16. package/dist/es2019/plugins/table/transforms/delete-columns.js +16 -5
  17. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  18. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  19. package/dist/es2019/plugins/table/ui/common-styles.js +0 -1
  20. package/dist/esm/plugins/table/commands/delete.js +12 -0
  21. package/dist/esm/plugins/table/commands-with-analytics.js +3 -8
  22. package/dist/esm/plugins/table/event-handlers.js +2 -2
  23. package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
  24. package/dist/esm/plugins/table/transforms/column-width.js +113 -7
  25. package/dist/esm/plugins/table/transforms/delete-columns.js +16 -6
  26. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  27. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +1 -1
  28. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  29. package/dist/types/plugins/table/commands/delete.d.ts +3 -0
  30. package/dist/types/plugins/table/event-handlers.d.ts +1 -1
  31. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  32. package/dist/types/plugins/table/transforms/column-width.d.ts +25 -6
  33. package/dist/types/plugins/table/transforms/delete-columns.d.ts +2 -1
  34. package/dist/types/plugins/table/ui/FloatingDeleteButton/index.d.ts +4 -4
  35. package/package.json +5 -2
  36. package/src/__tests__/unit/commands.ts +1 -0
  37. package/src/__tests__/unit/transforms/delete-columns.ts +406 -105
  38. package/src/__tests__/unit/undo-redo.ts +1 -1
  39. package/src/plugins/table/commands/delete.ts +20 -0
  40. package/src/plugins/table/commands-with-analytics.ts +3 -10
  41. package/src/plugins/table/event-handlers.ts +6 -1
  42. package/src/plugins/table/pm-plugins/main.ts +7 -1
  43. package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +1 -1
  44. package/src/plugins/table/transforms/column-width.ts +163 -17
  45. package/src/plugins/table/transforms/delete-columns.ts +23 -6
  46. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +1 -1
  47. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +7 -6
  48. package/src/plugins/table/ui/common-styles.ts +0 -1
  49. package/dist/types-ts4.5/i18n/cs.d.ts +0 -37
  50. package/dist/types-ts4.5/i18n/da.d.ts +0 -35
  51. package/dist/types-ts4.5/i18n/de.d.ts +0 -35
  52. package/dist/types-ts4.5/i18n/en.d.ts +0 -37
  53. package/dist/types-ts4.5/i18n/en_GB.d.ts +0 -37
  54. package/dist/types-ts4.5/i18n/en_ZZ.d.ts +0 -37
  55. package/dist/types-ts4.5/i18n/es.d.ts +0 -35
  56. package/dist/types-ts4.5/i18n/fi.d.ts +0 -35
  57. package/dist/types-ts4.5/i18n/fr.d.ts +0 -37
  58. package/dist/types-ts4.5/i18n/hu.d.ts +0 -37
  59. package/dist/types-ts4.5/i18n/it.d.ts +0 -37
  60. package/dist/types-ts4.5/i18n/ja.d.ts +0 -37
  61. package/dist/types-ts4.5/i18n/ko.d.ts +0 -35
  62. package/dist/types-ts4.5/i18n/nb.d.ts +0 -35
  63. package/dist/types-ts4.5/i18n/nl.d.ts +0 -37
  64. package/dist/types-ts4.5/i18n/pl.d.ts +0 -37
  65. package/dist/types-ts4.5/i18n/pt_BR.d.ts +0 -37
  66. package/dist/types-ts4.5/i18n/ru.d.ts +0 -37
  67. package/dist/types-ts4.5/i18n/sv.d.ts +0 -35
  68. package/dist/types-ts4.5/i18n/th.d.ts +0 -35
  69. package/dist/types-ts4.5/i18n/tr.d.ts +0 -37
  70. package/dist/types-ts4.5/i18n/uk.d.ts +0 -37
  71. package/dist/types-ts4.5/i18n/vi.d.ts +0 -35
  72. package/dist/types-ts4.5/i18n/zh.d.ts +0 -37
  73. package/dist/types-ts4.5/i18n/zh_TW.d.ts +0 -37
  74. package/dist/types-ts4.5/index.d.ts +0 -2
  75. package/dist/types-ts4.5/plugins/table/commands/clear.d.ts +0 -3
  76. package/dist/types-ts4.5/plugins/table/commands/collapse.d.ts +0 -2
  77. package/dist/types-ts4.5/plugins/table/commands/go-to-next-cell.d.ts +0 -4
  78. package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +0 -8
  79. package/dist/types-ts4.5/plugins/table/commands/index.d.ts +0 -8
  80. package/dist/types-ts4.5/plugins/table/commands/insert.d.ts +0 -9
  81. package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +0 -29
  82. package/dist/types-ts4.5/plugins/table/commands/referentiality.d.ts +0 -2
  83. package/dist/types-ts4.5/plugins/table/commands/selection.d.ts +0 -8
  84. package/dist/types-ts4.5/plugins/table/commands/sort.d.ts +0 -3
  85. package/dist/types-ts4.5/plugins/table/commands/split-cell.d.ts +0 -6
  86. package/dist/types-ts4.5/plugins/table/commands/toggle.d.ts +0 -12
  87. package/dist/types-ts4.5/plugins/table/commands-with-analytics.d.ts +0 -25
  88. package/dist/types-ts4.5/plugins/table/create-plugin-config.d.ts +0 -2
  89. package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +0 -15
  90. package/dist/types-ts4.5/plugins/table/handlers.d.ts +0 -3
  91. package/dist/types-ts4.5/plugins/table/index.d.ts +0 -45
  92. package/dist/types-ts4.5/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -24
  93. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +0 -73
  94. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +0 -44
  95. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +0 -25
  96. package/dist/types-ts4.5/plugins/table/nodeviews/TableStickyScrollbar.d.ts +0 -24
  97. package/dist/types-ts4.5/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
  98. package/dist/types-ts4.5/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
  99. package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +0 -33
  100. package/dist/types-ts4.5/plugins/table/nodeviews/tableCell.d.ts +0 -17
  101. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +0 -26
  102. package/dist/types-ts4.5/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -1
  103. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
  104. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
  105. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -4
  106. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
  107. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
  108. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
  109. package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +0 -4
  110. package/dist/types-ts4.5/plugins/table/pm-plugins/keymap.d.ts +0 -5
  111. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +0 -8
  112. package/dist/types-ts4.5/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
  113. package/dist/types-ts4.5/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
  114. package/dist/types-ts4.5/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
  115. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
  116. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
  117. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  118. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
  119. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
  120. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
  121. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
  122. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
  123. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
  124. package/dist/types-ts4.5/plugins/table/pm-plugins/table-analytics.d.ts +0 -23
  125. package/dist/types-ts4.5/plugins/table/pm-plugins/table-local-id.d.ts +0 -10
  126. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -23
  127. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
  128. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -3
  129. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
  130. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
  131. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
  132. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
  133. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -23
  134. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
  135. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/consts.d.ts +0 -2
  136. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
  137. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -12
  138. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -13
  139. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -20
  140. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
  141. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
  142. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
  143. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -21
  144. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
  145. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
  146. package/dist/types-ts4.5/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
  147. package/dist/types-ts4.5/plugins/table/pm-plugins/table-width.d.ts +0 -17
  148. package/dist/types-ts4.5/plugins/table/reducer.d.ts +0 -3
  149. package/dist/types-ts4.5/plugins/table/toolbar.d.ts +0 -36
  150. package/dist/types-ts4.5/plugins/table/transforms/column-width.d.ts +0 -18
  151. package/dist/types-ts4.5/plugins/table/transforms/delete-columns.d.ts +0 -3
  152. package/dist/types-ts4.5/plugins/table/transforms/delete-rows.d.ts +0 -3
  153. package/dist/types-ts4.5/plugins/table/transforms/fix-tables.d.ts +0 -9
  154. package/dist/types-ts4.5/plugins/table/transforms/index.d.ts +0 -6
  155. package/dist/types-ts4.5/plugins/table/transforms/merge.d.ts +0 -5
  156. package/dist/types-ts4.5/plugins/table/transforms/replace-table.d.ts +0 -5
  157. package/dist/types-ts4.5/plugins/table/transforms/split.d.ts +0 -9
  158. package/dist/types-ts4.5/plugins/table/types.d.ts +0 -342
  159. package/dist/types-ts4.5/plugins/table/ui/ColumnResizeWidget/index.d.ts +0 -9
  160. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualButton/FixedButton.d.ts +0 -23
  161. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -21
  162. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -3
  163. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
  164. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -23
  165. package/dist/types-ts4.5/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
  166. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -13
  167. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
  168. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
  169. package/dist/types-ts4.5/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
  170. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -13
  171. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
  172. package/dist/types-ts4.5/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
  173. package/dist/types-ts4.5/plugins/table/ui/LayoutButton/index.d.ts +0 -21
  174. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
  175. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
  176. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
  177. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +0 -39
  178. package/dist/types-ts4.5/plugins/table/ui/common-styles.d.ts +0 -9
  179. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +0 -50
  180. package/dist/types-ts4.5/plugins/table/ui/messages.d.ts +0 -63
  181. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +0 -15
  182. package/dist/types-ts4.5/plugins/table/utils/analytics.d.ts +0 -45
  183. package/dist/types-ts4.5/plugins/table/utils/collapse.d.ts +0 -29
  184. package/dist/types-ts4.5/plugins/table/utils/column-controls.d.ts +0 -10
  185. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +0 -19
  186. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +0 -20
  187. package/dist/types-ts4.5/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
  188. package/dist/types-ts4.5/plugins/table/utils/guidelines.d.ts +0 -2
  189. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +0 -11
  190. package/dist/types-ts4.5/plugins/table/utils/nodes.d.ts +0 -13
  191. package/dist/types-ts4.5/plugins/table/utils/paste.d.ts +0 -14
  192. package/dist/types-ts4.5/plugins/table/utils/row-controls.d.ts +0 -16
  193. package/dist/types-ts4.5/plugins/table/utils/selection.d.ts +0 -6
  194. package/dist/types-ts4.5/plugins/table/utils/snapping.d.ts +0 -10
  195. package/dist/types-ts4.5/plugins/table/utils/table.d.ts +0 -4
  196. package/dist/types-ts4.5/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
  197. package/dist/types-ts4.5/plugins/table-plugin.d.ts +0 -2
  198. package/dist/types-ts4.5/types/i18n.d.ts +0 -5
  199. package/tmp/api-report-tmp.d.ts +0 -112
@@ -26,6 +26,7 @@ import {
26
26
  tdEmpty,
27
27
  tr,
28
28
  } from '@atlaskit/editor-test-helpers/doc-builder';
29
+ import { ffTest } from '@atlassian/feature-flags-test-utils';
29
30
 
30
31
  import tablePlugin from '../../../plugins/table-plugin';
31
32
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
@@ -42,12 +43,27 @@ const colsToRect = (cols: Array<number>, noOfRows: number): Rect => ({
42
43
  const TABLE_LOCAL_ID = 'test-table-local-id';
43
44
 
44
45
  describe('table plugin -> transforms -> delete columns', () => {
46
+ const originalClientWidth = Object.getOwnPropertyDescriptor(
47
+ HTMLElement.prototype,
48
+ 'clientWidth',
49
+ );
45
50
  beforeAll(() => {
46
51
  uuid.setStatic(TABLE_LOCAL_ID);
52
+
53
+ Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
54
+ get() {
55
+ return 760;
56
+ },
57
+ });
47
58
  });
48
59
 
49
60
  afterAll(() => {
50
61
  uuid.setStatic(false);
62
+ Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
63
+ get() {
64
+ return originalClientWidth;
65
+ },
66
+ });
51
67
  });
52
68
 
53
69
  const createEditor = createProsemirrorEditorFactory();
@@ -65,132 +81,411 @@ describe('table plugin -> transforms -> delete columns', () => {
65
81
  doc,
66
82
  preset,
67
83
  pluginKey,
84
+ attachTo: document.body,
68
85
  });
69
86
 
70
87
  describe('when selection rect is given', () => {
71
88
  describe('when the first column is deleted', () => {
72
- it('should delete the column and move cursor to the first column', () => {
73
- const {
74
- editorView,
75
- refs: { nextCursorPos },
76
- } = editor(
77
- doc(
78
- p('text'),
79
- table()(
80
- tr(
81
- td({})(p('{nextCursorPos}')),
82
- td({})(p('c2')),
83
- td({})(p('c3')),
89
+ describe('should delete the column and move cursor to the first column', () => {
90
+ ffTest(
91
+ 'platform.editor.table-update-colwidths-after-column-is-deleted',
92
+ () => {
93
+ const {
94
+ editorView,
95
+ refs: { nextCursorPos },
96
+ } = editor(
97
+ doc(
98
+ p('text'),
99
+ table()(
100
+ tr(
101
+ td({})(p('{nextCursorPos}')),
102
+ td({})(p('c2')),
103
+ td({})(p('c3')),
104
+ ),
105
+ ),
84
106
  ),
85
- ),
86
- ),
87
- );
88
- const { state, dispatch } = editorView;
89
- dispatch(deleteColumns(colsToRect([0], 1))(state.tr));
90
- expect(editorView.state.doc).toEqualDocument(
91
- doc(
92
- p('text'),
93
- table({ localId: TABLE_LOCAL_ID })(
94
- tr(td({})(p('c2')), td()(p('c3'))),
95
- ),
96
- ),
107
+ );
108
+ const { state, dispatch } = editorView;
109
+ dispatch(deleteColumns(colsToRect([0], 1), true)(state.tr));
110
+ expect(editorView.state.doc).toEqualDocument(
111
+ doc(
112
+ p('text'),
113
+ table({ localId: TABLE_LOCAL_ID })(
114
+ tr(td({})(p('c2')), td()(p('c3'))),
115
+ ),
116
+ ),
117
+ );
118
+ expect(editorView.state.selection.from).toEqual(nextCursorPos);
119
+ },
120
+ () => {
121
+ const {
122
+ editorView,
123
+ refs: { nextCursorPos },
124
+ } = editor(
125
+ doc(
126
+ p('text'),
127
+ table()(
128
+ tr(
129
+ td({})(p('{nextCursorPos}')),
130
+ td({})(p('c2')),
131
+ td({})(p('c3')),
132
+ ),
133
+ ),
134
+ ),
135
+ );
136
+ const { state, dispatch } = editorView;
137
+ dispatch(deleteColumns(colsToRect([0], 1), true)(state.tr));
138
+ expect(editorView.state.doc).toEqualDocument(
139
+ doc(
140
+ p('text'),
141
+ table({ localId: TABLE_LOCAL_ID })(
142
+ tr(td({})(p('c2')), td()(p('c3'))),
143
+ ),
144
+ ),
145
+ );
146
+ expect(editorView.state.selection.from).toEqual(nextCursorPos);
147
+ },
97
148
  );
98
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
99
149
  });
100
150
  });
101
151
 
102
152
  describe('when middle column is deleted', () => {
103
- it('should delete the column and move cursor to the previous column', () => {
104
- const {
105
- editorView,
106
- refs: { nextCursorPos },
107
- } = editor(
108
- doc(
109
- p('text'),
110
- table()(
111
- tr(
112
- td({})(p('{nextCursorPos}')),
113
- td({})(p('c2')),
114
- td({})(p('c3')),
153
+ describe('should delete the column and move cursor to the previous column', () => {
154
+ ffTest(
155
+ 'platform.editor.table-update-colwidths-after-column-is-deleted',
156
+ () => {
157
+ const {
158
+ editorView,
159
+ refs: { nextCursorPos },
160
+ } = editor(
161
+ doc(
162
+ p('text'),
163
+ table()(
164
+ tr(
165
+ td({})(p('{nextCursorPos}')),
166
+ td({})(p('c2')),
167
+ td({})(p('c3')),
168
+ ),
169
+ ),
115
170
  ),
116
- ),
117
- ),
118
- );
119
- const { state, dispatch } = editorView;
120
- dispatch(deleteColumns(colsToRect([1], 1))(state.tr));
121
- expect(editorView.state.doc).toEqualDocument(
122
- doc(
123
- p('text'),
124
- table({ localId: TABLE_LOCAL_ID })(tr(tdEmpty, td()(p('c3')))),
125
- ),
171
+ );
172
+ const { state, dispatch } = editorView;
173
+ dispatch(deleteColumns(colsToRect([1], 1), true)(state.tr));
174
+ expect(editorView.state.doc).toEqualDocument(
175
+ doc(
176
+ p('text'),
177
+ table({ localId: TABLE_LOCAL_ID })(tr(tdEmpty, td()(p('c3')))),
178
+ ),
179
+ );
180
+ expect(editorView.state.selection.from).toEqual(nextCursorPos);
181
+ },
182
+ () => {
183
+ const {
184
+ editorView,
185
+ refs: { nextCursorPos },
186
+ } = editor(
187
+ doc(
188
+ p('text'),
189
+ table()(
190
+ tr(
191
+ td({})(p('{nextCursorPos}')),
192
+ td({})(p('c2')),
193
+ td({})(p('c3')),
194
+ ),
195
+ ),
196
+ ),
197
+ );
198
+ const { state, dispatch } = editorView;
199
+ dispatch(deleteColumns(colsToRect([1], 1), true)(state.tr));
200
+ expect(editorView.state.doc).toEqualDocument(
201
+ doc(
202
+ p('text'),
203
+ table({ localId: TABLE_LOCAL_ID })(tr(tdEmpty, td()(p('c3')))),
204
+ ),
205
+ );
206
+ expect(editorView.state.selection.from).toEqual(nextCursorPos);
207
+ },
126
208
  );
127
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
128
209
  });
129
210
  });
130
211
 
131
212
  describe('when multiple rows are selected', () => {
132
- it('should delete these columns', () => {
133
- const { editorView } = editor(
134
- doc(
135
- p('text'),
136
- table()(tr(tdCursor, td({})(p('c1')), td({})(p('c2')))),
137
- ),
138
- );
139
- const { state, dispatch } = editorView;
140
- dispatch(deleteColumns(colsToRect([0, 1], 1))(state.tr));
141
- expect(editorView.state.doc).toEqualDocument(
142
- doc(p('text'), table({ localId: TABLE_LOCAL_ID })(tr(td()(p('c2'))))),
213
+ describe('should delete these columns', () => {
214
+ ffTest(
215
+ 'platform.editor.table-update-colwidths-after-column-is-deleted',
216
+ () => {
217
+ const { editorView } = editor(
218
+ doc(
219
+ p('text'),
220
+ table()(tr(tdCursor, td({})(p('c1')), td({})(p('c2')))),
221
+ ),
222
+ );
223
+ const { state, dispatch } = editorView;
224
+ dispatch(deleteColumns(colsToRect([0, 1], 1), true)(state.tr));
225
+ expect(editorView.state.doc).toEqualDocument(
226
+ doc(
227
+ p('text'),
228
+ table({ localId: TABLE_LOCAL_ID })(tr(td()(p('c2')))),
229
+ ),
230
+ );
231
+ },
232
+ () => {
233
+ const { editorView } = editor(
234
+ doc(
235
+ p('text'),
236
+ table()(tr(tdCursor, td({})(p('c1')), td({})(p('c2')))),
237
+ ),
238
+ );
239
+ const { state, dispatch } = editorView;
240
+ dispatch(deleteColumns(colsToRect([0, 1], 1), true)(state.tr));
241
+ expect(editorView.state.doc).toEqualDocument(
242
+ doc(
243
+ p('text'),
244
+ table({ localId: TABLE_LOCAL_ID })(tr(td()(p('c2')))),
245
+ ),
246
+ );
247
+ },
143
248
  );
144
249
  });
145
250
  });
146
251
  });
147
252
 
148
253
  describe('when one column is selected', () => {
149
- it('should delete the column', () => {
150
- const { editorView } = editor(
151
- doc(
152
- p('text'),
153
- table()(
154
- tr(td({})(p('a1')), td({})(p('{<cell}a2')), td({})(p('a3'))),
155
- tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
156
- ),
157
- ),
254
+ describe('should delete the column', () => {
255
+ ffTest(
256
+ 'platform.editor.table-update-colwidths-after-column-is-deleted',
257
+ () => {
258
+ const { editorView } = editor(
259
+ doc(
260
+ p('text'),
261
+ table()(
262
+ tr(td({})(p('a1')), td({})(p('{<cell}a2')), td({})(p('a3'))),
263
+ tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
264
+ ),
265
+ ),
266
+ );
267
+ const { state, dispatch } = editorView;
268
+ dispatch(
269
+ deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
270
+ );
271
+ expect(editorView.state.doc).toEqualDocument(
272
+ doc(
273
+ p('text'),
274
+ table({ localId: TABLE_LOCAL_ID })(
275
+ tr(td({})(p('a1')), td({})(p('a3'))),
276
+ tr(td({})(p('b1')), td({})(p('b3'))),
277
+ ),
278
+ ),
279
+ );
280
+ },
281
+ () => {
282
+ const { editorView } = editor(
283
+ doc(
284
+ p('text'),
285
+ table()(
286
+ tr(td({})(p('a1')), td({})(p('{<cell}a2')), td({})(p('a3'))),
287
+ tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
288
+ ),
289
+ ),
290
+ );
291
+ const { state, dispatch } = editorView;
292
+ dispatch(
293
+ deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
294
+ );
295
+ expect(editorView.state.doc).toEqualDocument(
296
+ doc(
297
+ p('text'),
298
+ table({ localId: TABLE_LOCAL_ID })(
299
+ tr(td({})(p('a1')), td({})(p('a3'))),
300
+ tr(td({})(p('b1')), td({})(p('b3'))),
301
+ ),
302
+ ),
303
+ );
304
+ },
158
305
  );
159
- const { state, dispatch } = editorView;
160
- dispatch(deleteColumns(getSelectionRect(state.selection)!)(state.tr));
161
- expect(editorView.state.doc).toEqualDocument(
162
- doc(
163
- p('text'),
164
- table({ localId: TABLE_LOCAL_ID })(
165
- tr(td({})(p('a1')), td({})(p('a3'))),
166
- tr(td({})(p('b1')), td({})(p('b3'))),
167
- ),
168
- ),
306
+ });
307
+
308
+ describe('should update each cells colWidth', () => {
309
+ ffTest(
310
+ 'platform.editor.table-update-colwidths-after-column-is-deleted',
311
+ () => {
312
+ const { editorView } = editor(
313
+ doc(
314
+ table({ localId: TABLE_LOCAL_ID, layout: 'default', width: 760 })(
315
+ tr(
316
+ td({ colwidth: [401] })(p('{<>}')),
317
+ td({ colwidth: [105] })(p('')),
318
+ td({ colwidth: [253] })(p('')),
319
+ ),
320
+ ),
321
+ ),
322
+ );
323
+ const { dispatch, state } = editorView;
324
+ dispatch(
325
+ deleteColumns(colsToRect([1], 1), true, editorView)(state.tr),
326
+ );
327
+
328
+ expect(editorView.state.doc).toEqualDocument(
329
+ doc(
330
+ table({ localId: TABLE_LOCAL_ID, width: 760 })(
331
+ tr(
332
+ td({ colwidth: [460] })(p('')),
333
+ td({ colwidth: [289] })(p('')),
334
+ ),
335
+ ),
336
+ ),
337
+ );
338
+ },
339
+ () => {
340
+ const { editorView } = editor(
341
+ doc(
342
+ table({ localId: TABLE_LOCAL_ID, width: 691 })(
343
+ tr(
344
+ td({ colwidth: [230] })(p('')),
345
+ td({ colwidth: [230] })(p('')),
346
+ td({ colwidth: [230] })(p('')),
347
+ ),
348
+ ),
349
+ ),
350
+ );
351
+ const { dispatch, state } = editorView;
352
+
353
+ dispatch(
354
+ deleteColumns(colsToRect([1], 1), true, editorView)(state.tr),
355
+ );
356
+
357
+ expect(editorView.state.doc).toEqualDocument(
358
+ doc(
359
+ table({ localId: TABLE_LOCAL_ID, width: 691 })(
360
+ tr(
361
+ td({ colwidth: [230] })(p('')),
362
+ td({ colwidth: [230] })(p('')),
363
+ ),
364
+ ),
365
+ ),
366
+ );
367
+ },
169
368
  );
170
369
  });
171
370
  });
172
371
 
173
372
  describe('when multiple columns are selected', () => {
174
- it('should delete these column', () => {
175
- const { editorView } = editor(
176
- doc(
177
- p('text'),
178
- table()(
179
- tr(td({})(p('{<cell}a1')), td({})(p('a2')), td({})(p('a3'))),
180
- tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
181
- ),
182
- ),
373
+ describe('should delete these column', () => {
374
+ ffTest(
375
+ 'platform.editor.table-update-colwidths-after-column-is-deleted',
376
+ () => {
377
+ const { editorView } = editor(
378
+ doc(
379
+ p('text'),
380
+ table()(
381
+ tr(td({})(p('{<cell}a1')), td({})(p('a2')), td({})(p('a3'))),
382
+ tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
383
+ ),
384
+ ),
385
+ );
386
+ const { state, dispatch } = editorView;
387
+ dispatch(
388
+ deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
389
+ );
390
+ expect(editorView.state.doc).toEqualDocument(
391
+ doc(
392
+ p('text'),
393
+ table({ localId: TABLE_LOCAL_ID })(
394
+ tr(td({})(p('a3'))),
395
+ tr(td({})(p('b3'))),
396
+ ),
397
+ ),
398
+ );
399
+ },
400
+ () => {
401
+ const { editorView } = editor(
402
+ doc(
403
+ p('text'),
404
+ table()(
405
+ tr(td({})(p('{<cell}a1')), td({})(p('a2')), td({})(p('a3'))),
406
+ tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
407
+ ),
408
+ ),
409
+ );
410
+ const { state, dispatch } = editorView;
411
+ dispatch(
412
+ deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
413
+ );
414
+ expect(editorView.state.doc).toEqualDocument(
415
+ doc(
416
+ p('text'),
417
+ table({ localId: TABLE_LOCAL_ID })(
418
+ tr(td({})(p('a3'))),
419
+ tr(td({})(p('b3'))),
420
+ ),
421
+ ),
422
+ );
423
+ },
183
424
  );
184
- const { state, dispatch } = editorView;
185
- dispatch(deleteColumns(getSelectionRect(state.selection)!)(state.tr));
186
- expect(editorView.state.doc).toEqualDocument(
187
- doc(
188
- p('text'),
189
- table({ localId: TABLE_LOCAL_ID })(
190
- tr(td({})(p('a3'))),
191
- tr(td({})(p('b3'))),
192
- ),
193
- ),
425
+ });
426
+
427
+ describe('should update each cells colWidth', () => {
428
+ ffTest(
429
+ 'platform.editor.table-update-colwidths-after-column-is-deleted',
430
+ () => {
431
+ const { editorView } = editor(
432
+ doc(
433
+ table({ localId: TABLE_LOCAL_ID, layout: 'default', width: 760 })(
434
+ tr(
435
+ td({ colwidth: [401] })(p('{<cell}')),
436
+ td({ colwidth: [105] })(p('{cell>}')),
437
+ td({ colwidth: [253] })(p('')),
438
+ ),
439
+ ),
440
+ ),
441
+ );
442
+ const { dispatch, state } = editorView;
443
+ dispatch(
444
+ deleteColumns(
445
+ getSelectionRect(state.selection)!,
446
+ true,
447
+ editorView,
448
+ )(state.tr),
449
+ );
450
+
451
+ expect(editorView.state.doc).toEqualDocument(
452
+ doc(
453
+ table({ localId: TABLE_LOCAL_ID, width: 760 })(
454
+ tr(td({ colwidth: [749] })(p(''))),
455
+ ),
456
+ ),
457
+ );
458
+ },
459
+ () => {
460
+ const { editorView } = editor(
461
+ doc(
462
+ table({ localId: TABLE_LOCAL_ID, width: 691 })(
463
+ tr(
464
+ td({ colwidth: [401] })(p('{<cell}')),
465
+ td({ colwidth: [105] })(p('{cell>}')),
466
+ td({ colwidth: [253] })(p('')),
467
+ ),
468
+ ),
469
+ ),
470
+ );
471
+ const { dispatch, state } = editorView;
472
+
473
+ dispatch(
474
+ deleteColumns(
475
+ getSelectionRect(state.selection)!,
476
+ true,
477
+ editorView,
478
+ )(state.tr),
479
+ );
480
+
481
+ expect(editorView.state.doc).toEqualDocument(
482
+ doc(
483
+ table({ localId: TABLE_LOCAL_ID, width: 691 })(
484
+ tr(td({ colwidth: [253] })(p(''))),
485
+ ),
486
+ ),
487
+ );
488
+ },
194
489
  );
195
490
  });
196
491
  });
@@ -207,7 +502,9 @@ describe('table plugin -> transforms -> delete columns', () => {
207
502
  ),
208
503
  );
209
504
  const { state, dispatch } = editorView;
210
- dispatch(deleteColumns(getSelectionRect(state.selection)!)(state.tr));
505
+ dispatch(
506
+ deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
507
+ );
211
508
  expect(editorView.state.doc).toEqualDocument(
212
509
  doc(
213
510
  p('text'),
@@ -241,7 +538,9 @@ describe('table plugin -> transforms -> delete columns', () => {
241
538
  ),
242
539
  );
243
540
  const { state, dispatch } = editorView;
244
- dispatch(deleteColumns(getSelectionRect(state.selection)!)(state.tr));
541
+ dispatch(
542
+ deleteColumns(getSelectionRect(state.selection)!, false)(state.tr),
543
+ );
245
544
  expect(editorView.state.doc).toEqualDocument(
246
545
  doc(
247
546
  p('text'),
@@ -271,7 +570,9 @@ describe('table plugin -> transforms -> delete columns', () => {
271
570
  ),
272
571
  );
273
572
  const { state, dispatch } = editorView;
274
- dispatch(deleteColumns(getSelectionRect(state.selection)!)(state.tr));
573
+ dispatch(
574
+ deleteColumns(getSelectionRect(state.selection)!, false)(state.tr),
575
+ );
275
576
  expect(editorView.state.doc).toEqualDocument(
276
577
  doc(
277
578
  p('text'),
@@ -305,7 +606,7 @@ describe('table plugin -> transforms -> delete columns', () => {
305
606
  ),
306
607
  );
307
608
  const { state, dispatch } = editorView;
308
- dispatch(deleteColumns(colsToRect([0], 3))(state.tr));
609
+ dispatch(deleteColumns(colsToRect([0], 3), true)(state.tr));
309
610
  expect(editorView.state.doc).toEqualDocument(
310
611
  doc(
311
612
  table({ localId: TABLE_LOCAL_ID })(
@@ -355,7 +656,7 @@ describe('table plugin -> transforms -> delete columns', () => {
355
656
  ),
356
657
  );
357
658
  const { state, dispatch } = editorView;
358
- dispatch(deleteColumns(colsToRect([0], 4))(state.tr));
659
+ dispatch(deleteColumns(colsToRect([0], 4), true)(state.tr));
359
660
  expect(editorView.state.doc).toEqualDocument(
360
661
  doc(
361
662
  table({ localId: TABLE_LOCAL_ID })(
@@ -407,7 +708,7 @@ describe('table plugin -> transforms -> delete columns', () => {
407
708
  ),
408
709
  );
409
710
  const { state, dispatch } = editorView;
410
- dispatch(deleteColumns(colsToRect([1], 3))(state.tr));
711
+ dispatch(deleteColumns(colsToRect([1], 3), true)(state.tr));
411
712
  expect(editorView.state.doc).toEqualDocument(
412
713
  doc(
413
714
  table({ localId: TABLE_LOCAL_ID })(
@@ -454,7 +755,7 @@ describe('table plugin -> transforms -> delete columns', () => {
454
755
  ),
455
756
  );
456
757
  const { state, dispatch } = editorView;
457
- dispatch(deleteColumns(colsToRect([1], 4))(state.tr));
758
+ dispatch(deleteColumns(colsToRect([1], 4), true)(state.tr));
458
759
  expect(editorView.state.doc).toEqualDocument(
459
760
  doc(
460
761
  table({ localId: TABLE_LOCAL_ID })(
@@ -500,7 +801,7 @@ describe('table plugin -> transforms -> delete columns', () => {
500
801
  ),
501
802
  );
502
803
  const { state, dispatch } = editorView;
503
- dispatch(deleteColumns(colsToRect([1, 2], 3))(state.tr));
804
+ dispatch(deleteColumns(colsToRect([1, 2], 3), true)(state.tr));
504
805
  expect(editorView.state.doc).toEqualDocument(
505
806
  doc(
506
807
  table({ localId: TABLE_LOCAL_ID })(
@@ -53,7 +53,7 @@ const INSERT_COLUMN = (editorView: EditorView) =>
53
53
  );
54
54
  const DELETE_COLUMN = (editorView: EditorView) => {
55
55
  const { state, dispatch } = editorView;
56
- dispatch(deleteColumns(colsToRect([0], 1))(state.tr));
56
+ dispatch(deleteColumns(colsToRect([0], 1), true, editorView)(state.tr));
57
57
  };
58
58
  const SHORTCUT_ADD_COLUMN_BEFORE = (editorView: EditorView) =>
59
59
  sendKeyToPm(editorView, 'Ctrl-Alt-ArrowLeft');
@@ -0,0 +1,20 @@
1
+ import type { Command } from '@atlaskit/editor-common/types';
2
+ import type { Rect } from '@atlaskit/editor-tables/table-map';
3
+
4
+ import { deleteColumns } from '../transforms/delete-columns';
5
+ import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
6
+
7
+ export const deleteColumnsCommand =
8
+ (rect: Rect): Command =>
9
+ (state, dispatch, view) => {
10
+ const tr = deleteColumns(
11
+ rect,
12
+ getAllowAddColumnCustomStep(state),
13
+ view,
14
+ )(state.tr);
15
+ if (dispatch) {
16
+ dispatch(tr);
17
+ return true;
18
+ }
19
+ return false;
20
+ };