@atlaskit/editor-plugin-table 7.5.4 → 7.5.5

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 (202) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/commands/column-resize.js +3 -3
  3. package/dist/cjs/commands/delete.js +2 -2
  4. package/dist/cjs/commands/insert.js +15 -15
  5. package/dist/cjs/commands-with-analytics.js +7 -7
  6. package/dist/cjs/event-handlers.js +2 -2
  7. package/dist/cjs/nodeviews/TableComponent.js +46 -59
  8. package/dist/cjs/nodeviews/TableContainer.js +5 -5
  9. package/dist/cjs/nodeviews/TableResizer.js +12 -12
  10. package/dist/cjs/nodeviews/table.js +9 -9
  11. package/dist/cjs/plugin.js +58 -56
  12. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +13 -13
  13. package/dist/cjs/pm-plugins/keymap.js +6 -8
  14. package/dist/cjs/pm-plugins/main.js +4 -6
  15. package/dist/cjs/pm-plugins/sticky-headers/plugin.js +2 -3
  16. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +12 -12
  17. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  18. package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +4 -2
  19. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +2 -2
  20. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +3 -3
  21. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +3 -3
  22. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +11 -12
  23. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  24. package/dist/cjs/pm-plugins/table-width.js +6 -2
  25. package/dist/cjs/toolbar.js +21 -21
  26. package/dist/cjs/transforms/column-width.js +4 -4
  27. package/dist/cjs/transforms/delete-columns.js +2 -2
  28. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +53 -55
  29. package/dist/cjs/ui/FloatingContextualMenu/index.js +2 -4
  30. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +2 -2
  31. package/dist/cjs/ui/FloatingDragMenu/index.js +6 -6
  32. package/dist/cjs/ui/FloatingInsertButton/index.js +6 -7
  33. package/dist/cjs/utils/create.js +2 -5
  34. package/dist/cjs/utils/drag-menu.js +4 -4
  35. package/dist/es2019/commands/column-resize.js +3 -3
  36. package/dist/es2019/commands/delete.js +2 -2
  37. package/dist/es2019/commands/insert.js +12 -12
  38. package/dist/es2019/commands-with-analytics.js +6 -6
  39. package/dist/es2019/event-handlers.js +2 -2
  40. package/dist/es2019/nodeviews/TableComponent.js +25 -36
  41. package/dist/es2019/nodeviews/TableContainer.js +5 -5
  42. package/dist/es2019/nodeviews/TableResizer.js +12 -12
  43. package/dist/es2019/nodeviews/table.js +9 -9
  44. package/dist/es2019/plugin.js +17 -17
  45. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +6 -6
  46. package/dist/es2019/pm-plugins/keymap.js +5 -8
  47. package/dist/es2019/pm-plugins/main.js +3 -5
  48. package/dist/es2019/pm-plugins/sticky-headers/plugin.js +1 -1
  49. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +5 -5
  50. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  51. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +3 -1
  52. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
  53. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +2 -2
  54. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +3 -2
  55. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +12 -13
  56. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  57. package/dist/es2019/pm-plugins/table-width.js +6 -2
  58. package/dist/es2019/toolbar.js +15 -15
  59. package/dist/es2019/transforms/column-width.js +5 -5
  60. package/dist/es2019/transforms/delete-columns.js +2 -2
  61. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +9 -12
  62. package/dist/es2019/ui/FloatingContextualMenu/index.js +2 -4
  63. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +2 -2
  64. package/dist/es2019/ui/FloatingDragMenu/index.js +5 -5
  65. package/dist/es2019/ui/FloatingInsertButton/index.js +5 -6
  66. package/dist/es2019/utils/create.js +2 -5
  67. package/dist/es2019/utils/drag-menu.js +4 -4
  68. package/dist/esm/commands/column-resize.js +3 -3
  69. package/dist/esm/commands/delete.js +2 -2
  70. package/dist/esm/commands/insert.js +15 -15
  71. package/dist/esm/commands-with-analytics.js +7 -7
  72. package/dist/esm/event-handlers.js +2 -2
  73. package/dist/esm/nodeviews/TableComponent.js +45 -58
  74. package/dist/esm/nodeviews/TableContainer.js +5 -5
  75. package/dist/esm/nodeviews/TableResizer.js +12 -12
  76. package/dist/esm/nodeviews/table.js +9 -9
  77. package/dist/esm/plugin.js +58 -56
  78. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +13 -13
  79. package/dist/esm/pm-plugins/keymap.js +6 -8
  80. package/dist/esm/pm-plugins/main.js +4 -6
  81. package/dist/esm/pm-plugins/sticky-headers/plugin.js +2 -3
  82. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +12 -12
  83. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  84. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +3 -1
  85. package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
  86. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +2 -2
  87. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +4 -3
  88. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +13 -14
  89. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  90. package/dist/esm/pm-plugins/table-width.js +6 -2
  91. package/dist/esm/toolbar.js +21 -21
  92. package/dist/esm/transforms/column-width.js +5 -5
  93. package/dist/esm/transforms/delete-columns.js +2 -2
  94. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +53 -55
  95. package/dist/esm/ui/FloatingContextualMenu/index.js +2 -4
  96. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +2 -2
  97. package/dist/esm/ui/FloatingDragMenu/index.js +6 -6
  98. package/dist/esm/ui/FloatingInsertButton/index.js +6 -7
  99. package/dist/esm/utils/create.js +2 -5
  100. package/dist/esm/utils/drag-menu.js +4 -4
  101. package/dist/types/commands/column-resize.d.ts +1 -1
  102. package/dist/types/commands/delete.d.ts +1 -1
  103. package/dist/types/commands/insert.d.ts +7 -7
  104. package/dist/types/commands-with-analytics.d.ts +3 -3
  105. package/dist/types/event-handlers.d.ts +1 -1
  106. package/dist/types/nodeviews/TableComponent.d.ts +2 -3
  107. package/dist/types/nodeviews/TableContainer.d.ts +4 -4
  108. package/dist/types/nodeviews/TableResizer.d.ts +2 -2
  109. package/dist/types/nodeviews/table.d.ts +1 -1
  110. package/dist/types/nodeviews/types.d.ts +1 -0
  111. package/dist/types/plugin.d.ts +1 -0
  112. package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +1 -2
  113. package/dist/types/pm-plugins/keymap.d.ts +2 -2
  114. package/dist/types/pm-plugins/main.d.ts +1 -1
  115. package/dist/types/pm-plugins/sticky-headers/plugin.d.ts +2 -3
  116. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  117. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  118. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  119. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  120. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -1
  121. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -4
  122. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  123. package/dist/types/pm-plugins/table-width.d.ts +1 -2
  124. package/dist/types/toolbar.d.ts +2 -2
  125. package/dist/types/transforms/column-width.d.ts +1 -1
  126. package/dist/types/transforms/delete-columns.d.ts +1 -1
  127. package/dist/types/types.d.ts +1 -0
  128. package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
  129. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
  130. package/dist/types/ui/FloatingDragMenu/index.d.ts +2 -3
  131. package/dist/types/ui/FloatingInsertButton/index.d.ts +1 -2
  132. package/dist/types/utils/create.d.ts +1 -2
  133. package/dist/types/utils/drag-menu.d.ts +1 -1
  134. package/dist/types-ts4.5/commands/column-resize.d.ts +1 -1
  135. package/dist/types-ts4.5/commands/delete.d.ts +1 -1
  136. package/dist/types-ts4.5/commands/insert.d.ts +7 -7
  137. package/dist/types-ts4.5/commands-with-analytics.d.ts +3 -3
  138. package/dist/types-ts4.5/event-handlers.d.ts +1 -1
  139. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +2 -3
  140. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -4
  141. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -2
  142. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -1
  143. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  144. package/dist/types-ts4.5/plugin.d.ts +1 -0
  145. package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +1 -2
  146. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -2
  147. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  148. package/dist/types-ts4.5/pm-plugins/sticky-headers/plugin.d.ts +2 -3
  149. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  150. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  151. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  152. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  153. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -1
  154. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -4
  155. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  156. package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -2
  157. package/dist/types-ts4.5/toolbar.d.ts +2 -2
  158. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
  159. package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
  160. package/dist/types-ts4.5/types.d.ts +1 -0
  161. package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
  162. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
  163. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +2 -3
  164. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +1 -2
  165. package/dist/types-ts4.5/utils/create.d.ts +1 -2
  166. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  167. package/package.json +2 -2
  168. package/src/commands/column-resize.ts +4 -3
  169. package/src/commands/delete.ts +2 -2
  170. package/src/commands/insert.ts +15 -27
  171. package/src/commands-with-analytics.ts +6 -9
  172. package/src/event-handlers.ts +2 -2
  173. package/src/nodeviews/TableComponent.tsx +31 -46
  174. package/src/nodeviews/TableContainer.tsx +7 -7
  175. package/src/nodeviews/TableResizer.tsx +14 -14
  176. package/src/nodeviews/table.tsx +6 -5
  177. package/src/nodeviews/types.ts +1 -0
  178. package/src/plugin.tsx +12 -28
  179. package/src/pm-plugins/drag-and-drop/plugin.ts +10 -15
  180. package/src/pm-plugins/keymap.ts +6 -13
  181. package/src/pm-plugins/main.ts +3 -3
  182. package/src/pm-plugins/sticky-headers/plugin.ts +2 -11
  183. package/src/pm-plugins/table-resizing/event-handlers.ts +6 -4
  184. package/src/pm-plugins/table-resizing/utils/colgroup.ts +2 -2
  185. package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
  186. package/src/pm-plugins/table-resizing/utils/index.ts +1 -1
  187. package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
  188. package/src/pm-plugins/table-resizing/utils/resize-column.ts +5 -2
  189. package/src/pm-plugins/table-resizing/utils/resize-state.ts +18 -13
  190. package/src/pm-plugins/table-resizing/utils/scale-table.ts +14 -14
  191. package/src/pm-plugins/table-width.ts +4 -6
  192. package/src/toolbar.tsx +16 -19
  193. package/src/transforms/column-width.ts +7 -6
  194. package/src/transforms/delete-columns.ts +2 -2
  195. package/src/types.ts +1 -0
  196. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +11 -16
  197. package/src/ui/FloatingContextualMenu/index.tsx +0 -2
  198. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -3
  199. package/src/ui/FloatingDragMenu/index.tsx +4 -8
  200. package/src/ui/FloatingInsertButton/index.tsx +11 -22
  201. package/src/utils/create.ts +2 -5
  202. package/src/utils/drag-menu.ts +7 -12
@@ -30,10 +30,7 @@ import {
30
30
  toggleTable,
31
31
  } from '@atlaskit/editor-common/keymaps';
32
32
  import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
33
- import type {
34
- GetEditorContainerWidth,
35
- GetEditorFeatureFlags,
36
- } from '@atlaskit/editor-common/types';
33
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
37
34
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
38
35
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
39
36
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
@@ -72,8 +69,8 @@ const createTableWithAnalytics = (
72
69
  export function keymapPlugin(
73
70
  getEditorContainerWidth: GetEditorContainerWidth,
74
71
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
75
- getEditorFeatureFlags?: GetEditorFeatureFlags,
76
72
  dragAndDropEnabled?: boolean,
73
+ isTableScalingEnabled = false,
77
74
  ): SafePlugin {
78
75
  const list = {};
79
76
 
@@ -121,13 +118,13 @@ export function keymapPlugin(
121
118
 
122
119
  bindKeymapWithCommand(
123
120
  addColumnBefore.common!,
124
- addColumnBeforeCommand(getEditorContainerWidth),
121
+ addColumnBeforeCommand(isTableScalingEnabled),
125
122
  list,
126
123
  );
127
124
 
128
125
  bindKeymapWithCommand(
129
126
  addColumnAfter.common!,
130
- addColumnAfterCommand(getEditorContainerWidth),
127
+ addColumnAfterCommand(isTableScalingEnabled),
131
128
  list,
132
129
  );
133
130
 
@@ -182,10 +179,6 @@ export function keymapPlugin(
182
179
  }
183
180
 
184
181
  if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
185
- const { tablePreserveWidth = false } = getEditorFeatureFlags
186
- ? getEditorFeatureFlags()
187
- : {};
188
-
189
182
  bindKeymapWithCommand(
190
183
  startColumnResizing.common!,
191
184
  initiateKeyboardColumnResizing,
@@ -201,7 +194,7 @@ export function keymapPlugin(
201
194
  changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI)(
202
195
  -10,
203
196
  getEditorContainerWidth,
204
- tablePreserveWidth,
197
+ isTableScalingEnabled,
205
198
  INPUT_METHOD.SHORTCUT,
206
199
  ),
207
200
  list,
@@ -212,7 +205,7 @@ export function keymapPlugin(
212
205
  changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI)(
213
206
  10,
214
207
  getEditorContainerWidth,
215
- tablePreserveWidth,
208
+ isTableScalingEnabled,
216
209
  INPUT_METHOD.SHORTCUT,
217
210
  ),
218
211
  list,
@@ -114,6 +114,7 @@ export const createPlugin = (
114
114
  dragAndDropEnabled?: boolean,
115
115
  editorAnalyticsAPI?: EditorAnalyticsAPI,
116
116
  pluginInjectionApi?: PluginInjectionAPI,
117
+ isTableScalingEnabled?: boolean,
117
118
  ) => {
118
119
  const state = createPluginState(dispatch, {
119
120
  pluginConfig,
@@ -127,6 +128,7 @@ export const createPlugin = (
127
128
  isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
128
129
  isHeaderColumnEnabled: false,
129
130
  isDragAndDropEnabled: dragAndDropEnabled,
131
+ isTableScalingEnabled: isTableScalingEnabled,
130
132
  ...defaultHoveredCell,
131
133
  ...defaultTableSelection,
132
134
  getIntl,
@@ -188,8 +190,6 @@ export const createPlugin = (
188
190
  });
189
191
  }
190
192
 
191
- const { tablePreserveWidth = false } = getEditorFeatureFlags();
192
-
193
193
  if (tr) {
194
194
  // "fixTables" removes empty rows as we don't allow that in schema
195
195
  const updatedTr = handleCut(
@@ -198,7 +198,7 @@ export const createPlugin = (
198
198
  newState,
199
199
  editorAnalyticsAPI,
200
200
  editorViewRef || undefined,
201
- tablePreserveWidth,
201
+ isTableScalingEnabled,
202
202
  );
203
203
  return fixTables(updatedTr) || updatedTr;
204
204
  }
@@ -1,19 +1,10 @@
1
- import type {
2
- Dispatch,
3
- EventDispatcher,
4
- } from '@atlaskit/editor-common/event-dispatcher';
1
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
5
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
- import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
7
3
 
8
4
  import { pluginKey } from './plugin-key';
9
5
  import { createPluginState } from './plugin-state';
10
6
 
11
- export const createPlugin = (
12
- dispatch: Dispatch,
13
- eventDispatcher: EventDispatcher,
14
- initialState = () => [],
15
- getEditorFeatureFlags: GetEditorFeatureFlags,
16
- ) => {
7
+ export const createPlugin = (dispatch: Dispatch, initialState = () => []) => {
17
8
  return new SafePlugin({
18
9
  state: createPluginState(dispatch, initialState),
19
10
  key: pluginKey,
@@ -49,7 +49,7 @@ export const handleMouseDown = (
49
49
  const { state, dispatch } = view;
50
50
  const editorDisabled = !view.editable;
51
51
  const domAtPos = view.domAtPos.bind(view);
52
- const { tablePreserveWidth = false } = getEditorFeatureFlags();
52
+ const { isTableScalingEnabled = false } = getTablePluginState(state);
53
53
 
54
54
  if (
55
55
  editorDisabled ||
@@ -119,7 +119,7 @@ export const handleMouseDown = (
119
119
  tableRef: dom,
120
120
  start,
121
121
  domAtPos,
122
- tablePreserveWidth,
122
+ isTableScalingEnabled: isTableScalingEnabled,
123
123
  });
124
124
 
125
125
  if (
@@ -209,8 +209,9 @@ export const handleMouseDown = (
209
209
  colIndex,
210
210
  clientX - startX,
211
211
  dom,
212
+ originalTable,
212
213
  resizingSelectedColumns ? selectedColumns : undefined,
213
- tablePreserveWidth,
214
+ isTableScalingEnabled,
214
215
  );
215
216
 
216
217
  const resizedDelta = clientX - startX;
@@ -292,8 +293,9 @@ export const handleMouseDown = (
292
293
  colIndex,
293
294
  clientX - dragging.startX,
294
295
  dom,
296
+ table,
295
297
  undefined,
296
- tablePreserveWidth,
298
+ isTableScalingEnabled,
297
299
  );
298
300
 
299
301
  updateControls()(state);
@@ -95,7 +95,7 @@ export const generateColgroup = (table: PmNode, tableRef?: HTMLElement) => {
95
95
  export const insertColgroupFromNode = (
96
96
  tableRef: HTMLTableElement,
97
97
  table: PmNode,
98
- tablePreserveWidth = false,
98
+ isTableScalingEnabled = false,
99
99
  shouldRemove = true,
100
100
  ): HTMLCollection => {
101
101
  let colgroup = tableRef.querySelector('colgroup') as HTMLElement;
@@ -105,7 +105,7 @@ export const insertColgroupFromNode = (
105
105
 
106
106
  colgroup = renderColgroupFromNode(
107
107
  table,
108
- tablePreserveWidth ? tableRef : undefined,
108
+ isTableScalingEnabled ? tableRef : undefined,
109
109
  );
110
110
  if (shouldRemove) {
111
111
  tableRef.insertBefore(colgroup, tableRef.firstChild);
@@ -2,3 +2,5 @@ export const COLUMN_MIN_WIDTH = 48;
2
2
  export const TABLE_DEFAULT_WIDTH = 760;
3
3
  export const TABLE_MAX_WIDTH = 1800;
4
4
  export const MAX_SCALING_PERCENT = 0.3;
5
+ // Used to calculate the width of a table using the Editor width
6
+ export const TABLE_EDITOR_MARGIN = 76;
@@ -31,7 +31,7 @@ export {
31
31
  domCellAround,
32
32
  getTableMaxWidth,
33
33
  getTableElementWidth,
34
- getTableContainerElement,
34
+ getTableContainerElementWidth,
35
35
  } from './misc';
36
36
  export { updateControls, isClickNear, getResizeCellPos } from './dom';
37
37
  export {
@@ -150,9 +150,9 @@ export const getTableElementWidth = (table: PMNode) => {
150
150
  return calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
151
151
  }
152
152
 
153
- return getTableContainerElement(table);
153
+ return getTableContainerElementWidth(table);
154
154
  };
155
155
 
156
- export const getTableContainerElement = (table: PMNode) => {
156
+ export const getTableContainerElementWidth = (table: PMNode) => {
157
157
  return getTableContainerWidth(table);
158
158
  };
@@ -1,4 +1,6 @@
1
1
  // Resize a given column by an amount from the current state
2
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
+
2
4
  import { growColumn, shrinkColumn } from './resize-logic';
3
5
  import { updateColgroup } from './resize-state';
4
6
  import type { ResizeState } from './types';
@@ -8,8 +10,9 @@ export const resizeColumn = (
8
10
  colIndex: number,
9
11
  amount: number,
10
12
  tableRef: HTMLElement,
13
+ tableNode: PmNode,
11
14
  selectedColumns?: number[],
12
- tablePreserveWidth = false,
15
+ isTableScalingEnabled = false,
13
16
  ): ResizeState => {
14
17
  const newState =
15
18
  amount > 0
@@ -18,7 +21,7 @@ export const resizeColumn = (
18
21
  ? shrinkColumn(resizeState, colIndex, amount, selectedColumns)
19
22
  : resizeState;
20
23
 
21
- updateColgroup(newState, tableRef, tablePreserveWidth);
24
+ updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
22
25
 
23
26
  return newState;
24
27
  };
@@ -20,10 +20,14 @@ import {
20
20
  import type { ColumnState } from './column-state';
21
21
  import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
22
22
  import { syncStickyRowToTable } from './dom';
23
- import { getTableMaxWidth } from './misc';
23
+ import { getTableContainerElementWidth, getTableMaxWidth } from './misc';
24
24
  import type { ResizeState, ResizeStateWithAnalytics } from './types';
25
25
 
26
- import { MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
26
+ import {
27
+ COLUMN_MIN_WIDTH,
28
+ MAX_SCALING_PERCENT,
29
+ TABLE_DEFAULT_WIDTH,
30
+ } from './index';
27
31
 
28
32
  export const getResizeState = ({
29
33
  minWidth,
@@ -32,7 +36,7 @@ export const getResizeState = ({
32
36
  tableRef,
33
37
  start,
34
38
  domAtPos,
35
- tablePreserveWidth = false,
39
+ isTableScalingEnabled = false,
36
40
  }: {
37
41
  minWidth: number;
38
42
  maxSize: number;
@@ -40,7 +44,7 @@ export const getResizeState = ({
40
44
  tableRef: HTMLTableElement;
41
45
  start: number;
42
46
  domAtPos: (pos: number) => { node: Node; offset: number };
43
- tablePreserveWidth: boolean;
47
+ isTableScalingEnabled: boolean;
44
48
  }): ResizeState => {
45
49
  // If the table has been resized, we can use the column widths from the table node
46
50
  if (hasTableBeenResized(table)) {
@@ -63,23 +67,23 @@ export const getResizeState = ({
63
67
  };
64
68
  }
65
69
 
66
- const shouldReinsertColgroup = !tablePreserveWidth;
70
+ const shouldReinsertColgroup = !isTableScalingEnabled;
67
71
 
68
72
  // Getting the resize state from DOM
69
73
  const colgroupChildren = insertColgroupFromNode(
70
74
  tableRef,
71
75
  table,
72
- tablePreserveWidth,
76
+ isTableScalingEnabled,
73
77
  shouldReinsertColgroup, // don't reinsert colgroup when preserving table width - this causes widths to jump
74
78
  );
75
79
  const cols = Array.from(colgroupChildren).map((_, index) => {
76
80
  // If the table hasn't been resized and we have a table width attribute, we can use it
77
81
  // to calculate the widths of the columns
78
- if (tablePreserveWidth && table.attrs.width) {
82
+ if (isTableScalingEnabled && table.attrs.width) {
79
83
  return {
80
84
  index,
81
85
  width: table.attrs.width / colgroupChildren.length,
82
- minWidth: 48,
86
+ minWidth: COLUMN_MIN_WIDTH,
83
87
  };
84
88
  }
85
89
  const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
@@ -104,14 +108,15 @@ export const getResizeState = ({
104
108
  export const updateColgroup = (
105
109
  state: ResizeState,
106
110
  tableRef: HTMLElement,
107
- tablePreserveWidth?: boolean,
111
+ tableNode?: PMNode,
112
+ isTableScalingEnabled?: boolean,
108
113
  ): void => {
109
114
  const cols = tableRef.querySelectorAll('col');
110
115
 
111
116
  if (getBooleanFF('platform.editor.custom-table-width')) {
112
117
  const columnsCount = cols.length;
113
- if (tablePreserveWidth) {
114
- const tableWidth = parseInt(tableRef.dataset?.tableWidth || ''); // TODO - get this value from the table node, not the dom
118
+ if (isTableScalingEnabled && tableNode) {
119
+ const tableWidth = getTableContainerElementWidth(tableNode);
115
120
  if (tableWidth) {
116
121
  let renderWidth =
117
122
  tableRef.parentElement?.clientWidth || TABLE_DEFAULT_WIDTH;
@@ -349,7 +354,7 @@ export const getNewResizeStateFromSelectedColumns = (
349
354
  state: EditorState,
350
355
  domAtPos: (pos: number) => { node: Node; offset: number },
351
356
  getEditorContainerWidth: GetEditorContainerWidth,
352
- tablePreserveWidth = false,
357
+ isTableScalingEnabled = false,
353
358
  ): ResizeStateWithAnalytics | undefined => {
354
359
  // Fail early so that we don't do complex calculations for no reason
355
360
  const numColumnsSelected = rect.right - rect.left;
@@ -394,7 +399,7 @@ export const getNewResizeStateFromSelectedColumns = (
394
399
  tableRef,
395
400
  start: table.start,
396
401
  domAtPos,
397
- tablePreserveWidth,
402
+ isTableScalingEnabled,
398
403
  });
399
404
 
400
405
  const newResizeState = evenSelectedColumnsWidths(resizeState, rect);
@@ -39,7 +39,7 @@ export const scale = (
39
39
  tableRef: HTMLTableElement,
40
40
  options: ScaleOptions,
41
41
  domAtPos: DomAtPos,
42
- tablePreserveWidth = false,
42
+ isTableScalingEnabled = false,
43
43
  ): ResizeState | undefined => {
44
44
  /**
45
45
  * isBreakoutEnabled === true -> default center aligned
@@ -98,7 +98,7 @@ export const scale = (
98
98
  tableRef,
99
99
  start,
100
100
  domAtPos,
101
- tablePreserveWidth,
101
+ isTableScalingEnabled,
102
102
  });
103
103
 
104
104
  return scaleTableTo(resizeState, newWidth);
@@ -110,7 +110,7 @@ export const scaleWithParent = (
110
110
  table: PMNode,
111
111
  start: number,
112
112
  domAtPos: DomAtPos,
113
- tablePreserveWidth = false,
113
+ isTableScalingEnabled = false,
114
114
  ) => {
115
115
  const resizeState = getResizeState({
116
116
  minWidth: tableCellMinWidth,
@@ -119,7 +119,7 @@ export const scaleWithParent = (
119
119
  tableRef,
120
120
  start,
121
121
  domAtPos,
122
- tablePreserveWidth,
122
+ isTableScalingEnabled,
123
123
  });
124
124
 
125
125
  if (table.attrs.isNumberColumnEnabled) {
@@ -158,7 +158,7 @@ export const previewScaleTable = (
158
158
  tableRef: HTMLTableElement | null | undefined,
159
159
  options: ScaleOptions,
160
160
  domAtPos: DomAtPos,
161
- tablePreserveWidth: boolean = false,
161
+ isTableScalingEnabled: boolean = false,
162
162
  ) => {
163
163
  const { node, start, parentWidth } = options;
164
164
 
@@ -175,8 +175,8 @@ export const previewScaleTable = (
175
175
  }
176
176
 
177
177
  // If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
178
- // If we are scaling the table down with tablePreserveWidth, the colgroup widths may be scaled to a value that is not 48px.
179
- if (!hasTableBeenResized(node) && !tablePreserveWidth) {
178
+ // If we are scaling the table down with isTableScalingEnabled, the colgroup widths may be scaled to a value that is not 48px.
179
+ if (!hasTableBeenResized(node) && !isTableScalingEnabled) {
180
180
  syncStickyRowToTable(tableRef);
181
181
  return;
182
182
  }
@@ -188,12 +188,12 @@ export const previewScaleTable = (
188
188
  node,
189
189
  start,
190
190
  domAtPos,
191
- tablePreserveWidth,
191
+ isTableScalingEnabled,
192
192
  )
193
- : scale(tableRef, options, domAtPos, tablePreserveWidth);
193
+ : scale(tableRef, options, domAtPos, isTableScalingEnabled);
194
194
 
195
195
  if (resizeState) {
196
- updateColgroup(resizeState, tableRef, tablePreserveWidth);
196
+ updateColgroup(resizeState, tableRef, node, isTableScalingEnabled);
197
197
  }
198
198
  };
199
199
 
@@ -203,7 +203,7 @@ export const scaleTable =
203
203
  tableRef: HTMLTableElement | null | undefined,
204
204
  options: ScaleOptions,
205
205
  domAtPos: DomAtPos,
206
- tablePreserveWidth = false,
206
+ isTableScalingEnabled = false,
207
207
  ) =>
208
208
  (tr: Transaction) => {
209
209
  if (!tableRef) {
@@ -215,7 +215,7 @@ export const scaleTable =
215
215
  if (hasTableBeenResized(node) === false) {
216
216
  // If its not a re-sized table, we still want to re-create cols
217
217
  // To force reflow of columns upon delete.
218
- if (!tablePreserveWidth) {
218
+ if (!isTableScalingEnabled) {
219
219
  insertColgroupFromNode(tableRef, node);
220
220
  }
221
221
  tr.setMeta('scrollIntoView', false);
@@ -230,10 +230,10 @@ export const scaleTable =
230
230
  node,
231
231
  start,
232
232
  domAtPos,
233
- tablePreserveWidth,
233
+ isTableScalingEnabled,
234
234
  );
235
235
  } else {
236
- resizeState = scale(tableRef, options, domAtPos, tablePreserveWidth);
236
+ resizeState = scale(tableRef, options, domAtPos, isTableScalingEnabled);
237
237
  }
238
238
 
239
239
  if (resizeState) {
@@ -14,7 +14,6 @@ import {
14
14
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
15
15
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
16
16
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
17
- import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
18
17
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
19
18
  import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
20
19
  import {
@@ -24,6 +23,7 @@ import {
24
23
  } from '@atlaskit/editor-shared-styles';
25
24
  import { findTable } from '@atlaskit/editor-tables/utils';
26
25
 
26
+ import { getPluginState } from './plugin-factory';
27
27
  import { TABLE_MAX_WIDTH } from './table-resizing/utils';
28
28
 
29
29
  type __ReplaceStep = ReplaceStep & {
@@ -44,7 +44,6 @@ const createPlugin = (
44
44
  dispatch: Dispatch,
45
45
  dispatchAnalyticsEvent: DispatchAnalyticsEvent,
46
46
  fullWidthEnabled: boolean,
47
- getEditorFeatureFlags?: GetEditorFeatureFlags,
48
47
  ) => {
49
48
  return new SafePlugin({
50
49
  key: pluginKey,
@@ -123,10 +122,9 @@ const createPlugin = (
123
122
  tr.getMeta('referentialityTableInserted'),
124
123
  );
125
124
 
126
- const shouldPatchTable =
127
- fullWidthEnabled &&
128
- getEditorFeatureFlags &&
129
- getEditorFeatureFlags()['tablePreserveWidth'];
125
+ const { isTableScalingEnabled = false } = getPluginState(newState);
126
+
127
+ const shouldPatchTable = fullWidthEnabled && isTableScalingEnabled;
130
128
 
131
129
  if (
132
130
  !isReplaceDocumentOperation &&
package/src/toolbar.tsx CHANGED
@@ -169,7 +169,7 @@ export const getToolbarCellOptionsConfig = (
169
169
  { formatMessage }: ToolbarMenuContext,
170
170
  getEditorContainerWidth: GetEditorContainerWidth,
171
171
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
172
- tablePreserveWidth = false,
172
+ isTableScalingEnabled = false,
173
173
  ): FloatingToolbarDropdown<Command> => {
174
174
  const { top, bottom, right, left } = initialSelectionRect;
175
175
  const numberOfColumns = right - left;
@@ -188,11 +188,10 @@ export const getToolbarCellOptionsConfig = (
188
188
  const selectionRect = getClosestSelectionRect(state);
189
189
  const index = selectionRect?.right;
190
190
  if (index) {
191
- insertColumnWithAnalytics(
192
- getEditorContainerWidth,
193
- editorAnalyticsAPI,
194
- tablePreserveWidth,
195
- )(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
191
+ insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(
192
+ INPUT_METHOD.FLOATING_TB,
193
+ index,
194
+ )(state, dispatch, view);
196
195
  }
197
196
  return true;
198
197
  },
@@ -294,7 +293,7 @@ export const getToolbarCellOptionsConfig = (
294
293
  editorState,
295
294
  editorView.domAtPos.bind(editorView),
296
295
  getEditorContainerWidth,
297
- tablePreserveWidth,
296
+ isTableScalingEnabled,
298
297
  )
299
298
  : undefined;
300
299
  const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
@@ -462,19 +461,18 @@ export const getToolbarConfig =
462
461
  editorAnalyticsAPI,
463
462
  );
464
463
 
465
- const { tablePreserveWidth = false } = getEditorFeatureFlags();
464
+ const { isTableScalingEnabled = false } = getPluginState(state);
466
465
 
467
466
  let cellItems: Array<FloatingToolbarItem<Command>>;
468
467
  cellItems = pluginState.isDragAndDropEnabled
469
468
  ? []
470
469
  : getCellItems(
471
- config,
472
470
  state,
473
471
  getEditorView(),
474
472
  intl,
475
473
  getEditorContainerWidth,
476
474
  editorAnalyticsAPI,
477
- tablePreserveWidth,
475
+ isTableScalingEnabled,
478
476
  );
479
477
 
480
478
  let columnSettingsItems;
@@ -487,7 +485,7 @@ export const getToolbarConfig =
487
485
  intl,
488
486
  getEditorContainerWidth,
489
487
  editorAnalyticsAPI,
490
- tablePreserveWidth,
488
+ isTableScalingEnabled,
491
489
  )
492
490
  : [];
493
491
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
@@ -607,13 +605,12 @@ const separator = (hidden?: boolean): FloatingToolbarItem<Command> => {
607
605
  };
608
606
 
609
607
  const getCellItems = (
610
- pluginConfig: PluginConfig,
611
608
  state: EditorState,
612
609
  view: EditorView | null,
613
610
  { formatMessage }: ToolbarMenuContext,
614
611
  getEditorContainerWidth: GetEditorContainerWidth,
615
612
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
616
- tablePreserveWidth = false,
613
+ isTableScalingEnabled = false,
617
614
  ): Array<FloatingToolbarItem<Command>> => {
618
615
  const initialSelectionRect = getClosestSelectionRect(state);
619
616
  if (initialSelectionRect) {
@@ -624,7 +621,7 @@ const getCellItems = (
624
621
  { formatMessage },
625
622
  getEditorContainerWidth,
626
623
  editorAnalyticsAPI,
627
- tablePreserveWidth,
624
+ isTableScalingEnabled,
628
625
  );
629
626
  return [cellOptions, separator(cellOptions.hidden!)];
630
627
  }
@@ -635,7 +632,7 @@ export const getDistributeConfig =
635
632
  (
636
633
  getEditorContainerWidth: GetEditorContainerWidth,
637
634
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
638
- tablePreserveWidth = false,
635
+ isTableScalingEnabled = false,
639
636
  ): Command =>
640
637
  (state, dispatch, editorView) => {
641
638
  const selectionOrTableRect = getClosestSelectionOrTableRect(state);
@@ -647,7 +644,7 @@ export const getDistributeConfig =
647
644
  state,
648
645
  editorView.domAtPos.bind(editorView),
649
646
  getEditorContainerWidth,
650
- tablePreserveWidth,
647
+ isTableScalingEnabled,
651
648
  );
652
649
 
653
650
  if (newResizeStateWithAnalytics) {
@@ -668,7 +665,7 @@ const getColumnSettingItems = (
668
665
  { formatMessage }: ToolbarMenuContext,
669
666
  getEditorContainerWidth: GetEditorContainerWidth,
670
667
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
671
- tablePreserveWidth = false,
668
+ isTableScalingEnabled = false,
672
669
  ): Array<FloatingToolbarItem<Command>> => {
673
670
  const pluginState = getPluginState(editorState);
674
671
  const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
@@ -682,7 +679,7 @@ const getColumnSettingItems = (
682
679
  editorState,
683
680
  editorView.domAtPos.bind(editorView),
684
681
  getEditorContainerWidth,
685
- tablePreserveWidth,
682
+ isTableScalingEnabled,
686
683
  );
687
684
 
688
685
  const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
@@ -701,7 +698,7 @@ const getColumnSettingItems = (
701
698
  getDistributeConfig(
702
699
  getEditorContainerWidth,
703
700
  editorAnalyticsAPI,
704
- tablePreserveWidth,
701
+ isTableScalingEnabled,
705
702
  )(state, dispatch, view),
706
703
  disabled: !wouldChange,
707
704
  },
@@ -10,7 +10,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
10
10
 
11
11
  import type { ResizeState } from '../pm-plugins/table-resizing/utils';
12
12
  import {
13
- getTableContainerElement,
13
+ getTableContainerElementWidth,
14
14
  getTableElementWidth,
15
15
  hasTableBeenResized,
16
16
  } from '../pm-plugins/table-resizing/utils';
@@ -108,7 +108,7 @@ export const updateColumnWidths =
108
108
  * @returns Updated transaction with rescaled columns for a given table
109
109
  */
110
110
  export const rescaleColumns =
111
- (tablePreserveWidth = false) =>
111
+ (isTableScalingEnabled = false) =>
112
112
  (table: ContentNodeWithPos, view: EditorView | undefined) =>
113
113
  (tr: Transaction): Transaction => {
114
114
  if (!view) {
@@ -132,13 +132,14 @@ export const rescaleColumns =
132
132
  isResized,
133
133
  };
134
134
 
135
- if (tablePreserveWidth) {
135
+ if (isTableScalingEnabled) {
136
136
  previousTableInfo = {
137
137
  // TODO - ensure correct width is returned when table doesn't have a width value
138
138
  width: getTableElementWidth(table.node),
139
139
  possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width')
140
- ? getTableContainerElement(table.node)
141
- : getTableContainerElement(table.node) - insertColumnButtonOffset,
140
+ ? getTableContainerElementWidth(table.node)
141
+ : getTableContainerElementWidth(table.node) -
142
+ insertColumnButtonOffset,
142
143
  isResized,
143
144
  };
144
145
  } else {
@@ -216,7 +217,7 @@ export const rescaleColumns =
216
217
  tableRef,
217
218
  domAtPos,
218
219
  maxSize: previousTableInfo.possibleMaxWidth,
219
- tablePreserveWidth,
220
+ isTableScalingEnabled,
220
221
  });
221
222
 
222
223
  // Two scenarios that require scaling:
@@ -253,7 +253,7 @@ export const deleteColumns =
253
253
  rect: Rect,
254
254
  allowCustomStep: boolean,
255
255
  view?: EditorView,
256
- tablePreserveWidth = false,
256
+ isTableScalingEnabled = false,
257
257
  ) =>
258
258
  (tr: Transaction) => {
259
259
  let updatedTr = tr;
@@ -269,7 +269,7 @@ export const deleteColumns =
269
269
  const table = findTable(updatedTr.selection);
270
270
 
271
271
  if (table) {
272
- updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
272
+ updatedTr = rescaleColumns(isTableScalingEnabled)(table, view)(updatedTr);
273
273
  }
274
274
  return updatedTr;
275
275
  };
package/src/types.ts CHANGED
@@ -138,6 +138,7 @@ export interface TablePluginState {
138
138
  isTableResizingEnabled?: boolean;
139
139
  isDragAndDropEnabled?: boolean;
140
140
  isTableHovered?: boolean;
141
+ isTableScalingEnabled?: boolean;
141
142
  }
142
143
 
143
144
  export type TablePluginAction =