@atlaskit/editor-plugin-table 7.16.13 → 7.16.15

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 (158) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/commands/column-resize.js +6 -3
  3. package/dist/cjs/commands/delete.js +2 -1
  4. package/dist/cjs/commands/insert.js +8 -5
  5. package/dist/cjs/commands/misc.js +17 -1
  6. package/dist/cjs/commands-with-analytics.js +6 -4
  7. package/dist/cjs/event-handlers.js +2 -1
  8. package/dist/cjs/nodeviews/TableComponent.js +21 -10
  9. package/dist/cjs/nodeviews/TableContainer.js +7 -3
  10. package/dist/cjs/nodeviews/TableResizer.js +3 -2
  11. package/dist/cjs/plugin.js +4 -3
  12. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +4 -2
  13. package/dist/cjs/pm-plugins/keymap.js +5 -4
  14. package/dist/cjs/pm-plugins/main.js +2 -2
  15. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +12 -7
  16. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +6 -5
  17. package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +2 -1
  18. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
  19. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +6 -4
  20. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  21. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +13 -8
  22. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +17 -9
  23. package/dist/cjs/toolbar.js +10 -5
  24. package/dist/cjs/transforms/column-width.js +3 -1
  25. package/dist/cjs/transforms/delete-columns.js +2 -1
  26. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +4 -2
  27. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +3 -2
  28. package/dist/cjs/ui/FloatingDragMenu/index.js +4 -1
  29. package/dist/cjs/ui/FloatingInsertButton/index.js +3 -1
  30. package/dist/cjs/utils/drag-menu.js +2 -1
  31. package/dist/es2019/commands/column-resize.js +6 -3
  32. package/dist/es2019/commands/delete.js +2 -2
  33. package/dist/es2019/commands/insert.js +8 -8
  34. package/dist/es2019/commands/misc.js +17 -1
  35. package/dist/es2019/commands-with-analytics.js +6 -6
  36. package/dist/es2019/event-handlers.js +2 -2
  37. package/dist/es2019/nodeviews/TableComponent.js +21 -10
  38. package/dist/es2019/nodeviews/TableContainer.js +7 -3
  39. package/dist/es2019/nodeviews/TableResizer.js +3 -2
  40. package/dist/es2019/plugin.js +4 -3
  41. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +4 -2
  42. package/dist/es2019/pm-plugins/keymap.js +5 -5
  43. package/dist/es2019/pm-plugins/main.js +2 -2
  44. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +12 -7
  45. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +6 -6
  46. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +1 -0
  47. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
  48. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +7 -5
  49. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +5 -5
  50. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +12 -8
  51. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +17 -12
  52. package/dist/es2019/toolbar.js +10 -8
  53. package/dist/es2019/transforms/column-width.js +3 -2
  54. package/dist/es2019/transforms/delete-columns.js +2 -2
  55. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +4 -2
  56. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +3 -2
  57. package/dist/es2019/ui/FloatingDragMenu/index.js +4 -1
  58. package/dist/es2019/ui/FloatingInsertButton/index.js +3 -1
  59. package/dist/es2019/utils/drag-menu.js +2 -2
  60. package/dist/esm/commands/column-resize.js +6 -3
  61. package/dist/esm/commands/delete.js +2 -1
  62. package/dist/esm/commands/insert.js +8 -5
  63. package/dist/esm/commands/misc.js +17 -1
  64. package/dist/esm/commands-with-analytics.js +6 -4
  65. package/dist/esm/event-handlers.js +2 -1
  66. package/dist/esm/nodeviews/TableComponent.js +21 -10
  67. package/dist/esm/nodeviews/TableContainer.js +7 -3
  68. package/dist/esm/nodeviews/TableResizer.js +3 -2
  69. package/dist/esm/plugin.js +4 -3
  70. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +4 -2
  71. package/dist/esm/pm-plugins/keymap.js +5 -4
  72. package/dist/esm/pm-plugins/main.js +2 -2
  73. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +12 -7
  74. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +6 -5
  75. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +1 -0
  76. package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
  77. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +7 -5
  78. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  79. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +13 -8
  80. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +17 -9
  81. package/dist/esm/toolbar.js +10 -5
  82. package/dist/esm/transforms/column-width.js +3 -1
  83. package/dist/esm/transforms/delete-columns.js +2 -1
  84. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +4 -2
  85. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +3 -2
  86. package/dist/esm/ui/FloatingDragMenu/index.js +4 -1
  87. package/dist/esm/ui/FloatingInsertButton/index.js +3 -1
  88. package/dist/esm/utils/drag-menu.js +2 -1
  89. package/dist/types/commands/delete.d.ts +1 -1
  90. package/dist/types/commands/insert.d.ts +4 -4
  91. package/dist/types/commands-with-analytics.d.ts +3 -3
  92. package/dist/types/event-handlers.d.ts +1 -1
  93. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  94. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  95. package/dist/types/pm-plugins/keymap.d.ts +1 -1
  96. package/dist/types/pm-plugins/main.d.ts +1 -1
  97. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
  98. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  99. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  100. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +2 -2
  101. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -2
  102. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +3 -2
  103. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -3
  104. package/dist/types/toolbar.d.ts +2 -2
  105. package/dist/types/transforms/column-width.d.ts +1 -1
  106. package/dist/types/transforms/delete-columns.d.ts +1 -1
  107. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  108. package/dist/types/utils/drag-menu.d.ts +1 -1
  109. package/dist/types-ts4.5/commands/delete.d.ts +1 -1
  110. package/dist/types-ts4.5/commands/insert.d.ts +4 -4
  111. package/dist/types-ts4.5/commands-with-analytics.d.ts +3 -3
  112. package/dist/types-ts4.5/event-handlers.d.ts +1 -1
  113. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  114. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  115. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +1 -1
  116. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  117. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +2 -2
  118. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  119. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  120. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +2 -2
  121. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -2
  122. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +3 -2
  123. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -3
  124. package/dist/types-ts4.5/toolbar.d.ts +2 -2
  125. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
  126. package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
  127. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  128. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  129. package/package.json +4 -1
  130. package/src/commands/column-resize.ts +9 -3
  131. package/src/commands/delete.ts +2 -1
  132. package/src/commands/insert.ts +31 -12
  133. package/src/commands/misc.ts +20 -4
  134. package/src/commands-with-analytics.ts +24 -8
  135. package/src/event-handlers.ts +2 -0
  136. package/src/nodeviews/TableComponent.tsx +41 -12
  137. package/src/nodeviews/TableContainer.tsx +6 -0
  138. package/src/nodeviews/TableResizer.tsx +4 -0
  139. package/src/plugin.tsx +9 -0
  140. package/src/pm-plugins/drag-and-drop/plugin.ts +13 -4
  141. package/src/pm-plugins/keymap.ts +17 -4
  142. package/src/pm-plugins/main.ts +2 -0
  143. package/src/pm-plugins/table-resizing/event-handlers.ts +21 -10
  144. package/src/pm-plugins/table-resizing/utils/colgroup.ts +14 -4
  145. package/src/pm-plugins/table-resizing/utils/consts.ts +1 -0
  146. package/src/pm-plugins/table-resizing/utils/index.ts +1 -0
  147. package/src/pm-plugins/table-resizing/utils/misc.ts +24 -5
  148. package/src/pm-plugins/table-resizing/utils/resize-column.ts +11 -4
  149. package/src/pm-plugins/table-resizing/utils/resize-state.ts +17 -6
  150. package/src/pm-plugins/table-resizing/utils/scale-table.ts +32 -9
  151. package/src/toolbar.tsx +18 -10
  152. package/src/transforms/column-width.ts +2 -1
  153. package/src/transforms/delete-columns.ts +11 -2
  154. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +12 -5
  155. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -0
  156. package/src/ui/FloatingDragMenu/index.tsx +7 -0
  157. package/src/ui/FloatingInsertButton/index.tsx +7 -0
  158. package/src/utils/drag-menu.ts +2 -0
package/src/plugin.tsx CHANGED
@@ -153,6 +153,11 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
153
153
  };
154
154
  const editorAnalyticsAPI = api?.analytics?.actions;
155
155
 
156
+ const shouldUseIncreasedScalingPercent =
157
+ options?.isTableScalingEnabled &&
158
+ getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') &&
159
+ getBooleanFF('platform.editor.table.use-increased-scaling-percent');
160
+
156
161
  return {
157
162
  name: 'table',
158
163
 
@@ -278,6 +283,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
278
283
  api,
279
284
  isTableScalingEnabled,
280
285
  isTableAlignmentEnabled,
286
+ shouldUseIncreasedScalingPercent,
281
287
  );
282
288
  },
283
289
  },
@@ -313,6 +319,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
313
319
  isTableAlignmentEnabled = false,
314
320
  fullWidthEnabled = false,
315
321
  } = options || ({} as TablePluginOptions);
322
+
316
323
  return keymapPlugin(
317
324
  defaultGetEditorContainerWidth,
318
325
  editorAnalyticsAPI,
@@ -322,6 +329,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
322
329
  fullWidthEnabled,
323
330
  api,
324
331
  getIntl,
332
+ shouldUseIncreasedScalingPercent,
325
333
  );
326
334
  },
327
335
  },
@@ -652,6 +660,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
652
660
  options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags,
653
661
  () => editorViewRef.current,
654
662
  options,
663
+ shouldUseIncreasedScalingPercent,
655
664
  )(pluginConfig(options?.tableOptions)),
656
665
  },
657
666
  };
@@ -214,14 +214,23 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
214
214
  const { isTableScalingEnabled = false } = getTablePluginState(editorView.state);
215
215
 
216
216
  let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
217
- if (
217
+ const isTableScalingEnabledWithLockButton =
218
218
  isTableScalingEnabled &&
219
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')
220
- ) {
219
+ getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
220
+ const shouldUseIncreasedScalingPercent =
221
+ isTableScalingEnabledWithLockButton &&
222
+ getBooleanFF('platform.editor.table.use-increased-scaling-percent');
223
+
224
+ if (isTableScalingEnabledWithLockButton) {
221
225
  isTableScalingEnabledOnCurrentTable = tableNode.attrs.displayMode !== 'fixed';
222
226
  }
223
227
 
224
- insertColgroupFromNode(tableRef, tableNode, isTableScalingEnabledOnCurrentTable);
228
+ insertColgroupFromNode(
229
+ tableRef,
230
+ tableNode,
231
+ isTableScalingEnabledOnCurrentTable,
232
+ shouldUseIncreasedScalingPercent,
233
+ );
225
234
  }
226
235
  }
227
236
 
@@ -61,6 +61,7 @@ export function keymapPlugin(
61
61
  isFullWidthEnabled?: boolean,
62
62
  pluginInjectionApi?: PluginInjectionAPIWithA11y,
63
63
  getIntl?: () => IntlShape,
64
+ shouldUseIncreasedScalingPercent?: boolean,
64
65
  ): SafePlugin {
65
66
  const list = {};
66
67
 
@@ -111,11 +112,15 @@ export function keymapPlugin(
111
112
 
112
113
  bindKeymapWithCommand(
113
114
  addColumnBefore.common!,
114
- addColumnBeforeCommand(isTableScalingEnabled),
115
+ addColumnBeforeCommand(isTableScalingEnabled, shouldUseIncreasedScalingPercent),
115
116
  list,
116
117
  );
117
118
 
118
- bindKeymapWithCommand(addColumnAfter.common!, addColumnAfterCommand(isTableScalingEnabled), list);
119
+ bindKeymapWithCommand(
120
+ addColumnAfter.common!,
121
+ addColumnAfterCommand(isTableScalingEnabled, shouldUseIncreasedScalingPercent),
122
+ list,
123
+ );
119
124
 
120
125
  if (dragAndDropEnabled) {
121
126
  // Move row/column shortcuts
@@ -153,13 +158,21 @@ export function keymapPlugin(
153
158
  // Delete row/column shortcuts
154
159
  bindKeymapWithCommand(
155
160
  deleteColumn.common!,
156
- deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI),
161
+ deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(
162
+ editorAnalyticsAPI,
163
+ isTableScalingEnabled,
164
+ shouldUseIncreasedScalingPercent,
165
+ ),
157
166
  list,
158
167
  );
159
168
 
160
169
  bindKeymapWithCommand(
161
170
  deleteRow.common!,
162
- deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI),
171
+ deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(
172
+ editorAnalyticsAPI,
173
+ isTableScalingEnabled,
174
+ shouldUseIncreasedScalingPercent,
175
+ ),
163
176
  list,
164
177
  );
165
178
  }
@@ -93,6 +93,7 @@ export const createPlugin = (
93
93
  pluginInjectionApi?: PluginInjectionAPI,
94
94
  isTableScalingEnabled?: boolean,
95
95
  isTableAlignmentEnabled?: boolean,
96
+ shouldUseIncreasedScalingPercent?: boolean,
96
97
  ) => {
97
98
  const state = createPluginState(dispatch, {
98
99
  pluginConfig,
@@ -165,6 +166,7 @@ export const createPlugin = (
165
166
  editorAnalyticsAPI,
166
167
  editorViewRef || undefined,
167
168
  isTableScalingEnabled,
169
+ shouldUseIncreasedScalingPercent,
168
170
  );
169
171
  return fixTables(updatedTr) || updatedTr;
170
172
  }
@@ -84,10 +84,10 @@ export const handleMouseDown = (
84
84
  });
85
85
 
86
86
  let shouldScale = tableDepth === 0 && isTableScalingEnabled;
87
- if (
88
- isTableScalingEnabled &&
89
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')
90
- ) {
87
+
88
+ const isTableScalingEnabledWithLockButton =
89
+ isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
90
+ if (isTableScalingEnabledWithLockButton) {
91
91
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
92
92
  }
93
93
 
@@ -99,6 +99,9 @@ export const handleMouseDown = (
99
99
  start,
100
100
  domAtPos,
101
101
  isTableScalingEnabled: shouldScale,
102
+ shouldUseIncreasedScalingPercent:
103
+ isTableScalingEnabledWithLockButton &&
104
+ getBooleanFF('platform.editor.table.use-increased-scaling-percent'),
102
105
  });
103
106
 
104
107
  if (
@@ -180,10 +183,10 @@ export const handleMouseDown = (
180
183
  selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
181
184
 
182
185
  let shouldScale = tableDepth === 0 && isTableScalingEnabled;
183
- if (
186
+ const isTableScalingEnabledWithLockButton =
184
187
  isTableScalingEnabled &&
185
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')
186
- ) {
188
+ getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
189
+ if (isTableScalingEnabledWithLockButton) {
187
190
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
188
191
  }
189
192
 
@@ -210,6 +213,8 @@ export const handleMouseDown = (
210
213
  originalTable,
211
214
  resizingSelectedColumns ? selectedColumns : undefined,
212
215
  shouldScale,
216
+ isTableScalingEnabledWithLockButton &&
217
+ getBooleanFF('platform.editor.table.use-increased-scaling-percent'),
213
218
  );
214
219
  tr = updateColumnWidths(newResizeState, table, start)(tr);
215
220
  }
@@ -284,10 +289,13 @@ export const handleMouseDown = (
284
289
  const colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter!.attrs.colspan - 1;
285
290
 
286
291
  let shouldScale = tableDepth === 0 && isTableScalingEnabled;
287
- if (
292
+ const isTableScalingEnabledWithLockButton =
288
293
  isTableScalingEnabled &&
289
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')
290
- ) {
294
+ getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
295
+ const shouldUseIncreasedScalingPercent =
296
+ isTableScalingEnabledWithLockButton &&
297
+ getBooleanFF('platform.editor.table.use-increased-scaling-percent');
298
+ if (isTableScalingEnabledWithLockButton) {
291
299
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
292
300
  }
293
301
 
@@ -300,6 +308,8 @@ export const handleMouseDown = (
300
308
  table,
301
309
  undefined,
302
310
  shouldScale,
311
+ undefined,
312
+ shouldUseIncreasedScalingPercent,
303
313
  );
304
314
  } else {
305
315
  resizeColumn(
@@ -310,6 +320,7 @@ export const handleMouseDown = (
310
320
  table,
311
321
  undefined,
312
322
  shouldScale,
323
+ shouldUseIncreasedScalingPercent,
313
324
  );
314
325
  }
315
326
 
@@ -17,9 +17,12 @@ type Col = Array<string | { [name: string]: string }>;
17
17
  export const getColWidthFix = (colwidth: number, tableColumnCount: number) =>
18
18
  colwidth - 1 / tableColumnCount;
19
19
 
20
- export const generateColgroup = (table: PmNode, tableRef?: HTMLElement) => {
20
+ export const generateColgroup = (
21
+ table: PmNode,
22
+ tableRef?: HTMLElement,
23
+ shouldUseIncreasedScalingPercent?: boolean,
24
+ ) => {
21
25
  const cols: Col[] = [];
22
-
23
26
  const map = TableMap.get(table);
24
27
  table.content.firstChild!.content.forEach((cell) => {
25
28
  const colspan = cell.attrs.colspan || 1;
@@ -27,7 +30,11 @@ export const generateColgroup = (table: PmNode, tableRef?: HTMLElement) => {
27
30
  // We slice here to guard against our colwidth array having more entries
28
31
  // Than the we actually span. We'll patch the document at a later point.
29
32
  if (tableRef) {
30
- const scalePercent = getTableScalingPercent(table, tableRef);
33
+ const scalePercent = getTableScalingPercent(
34
+ table,
35
+ tableRef,
36
+ shouldUseIncreasedScalingPercent,
37
+ );
31
38
  cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
32
39
  const fixedColWidth = getColWidthFix(width, map.width);
33
40
  const scaledWidth = fixedColWidth * scalePercent;
@@ -73,6 +80,7 @@ export const insertColgroupFromNode = (
73
80
  table: PmNode,
74
81
  isTableScalingEnabled = false,
75
82
  shouldRemove = true,
83
+ shouldUseIncreasedScalingPercent = false,
76
84
  ): HTMLCollection => {
77
85
  let colgroup = tableRef?.querySelector('colgroup') as HTMLElement;
78
86
  if (colgroup && shouldRemove) {
@@ -82,6 +90,7 @@ export const insertColgroupFromNode = (
82
90
  colgroup = renderColgroupFromNode(
83
91
  table,
84
92
  isTableScalingEnabled ? tableRef ?? undefined : undefined,
93
+ shouldUseIncreasedScalingPercent,
85
94
  );
86
95
  if (shouldRemove) {
87
96
  tableRef?.insertBefore(colgroup, tableRef?.firstChild);
@@ -117,11 +126,12 @@ export const isMinCellWidthTable = (table: PmNode) => {
117
126
  function renderColgroupFromNode(
118
127
  table: PmNode,
119
128
  maybeTableRef: HTMLElement | undefined,
129
+ shouldUseIncreasedScalingPercent: boolean,
120
130
  ): HTMLElement {
121
131
  const rendered = DOMSerializer.renderSpec(document, [
122
132
  'colgroup',
123
133
  {},
124
- ...generateColgroup(table, maybeTableRef),
134
+ ...generateColgroup(table, maybeTableRef, shouldUseIncreasedScalingPercent),
125
135
  ]);
126
136
 
127
137
  return rendered.dom as HTMLElement;
@@ -2,5 +2,6 @@ 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
+ export const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
5
6
  // Used to calculate the width of a table using the Editor width
6
7
  export const TABLE_EDITOR_MARGIN = 76;
@@ -43,4 +43,5 @@ export {
43
43
  TABLE_MAX_WIDTH,
44
44
  TABLE_DEFAULT_WIDTH,
45
45
  MAX_SCALING_PERCENT,
46
+ MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION,
46
47
  } from './consts';
@@ -20,7 +20,10 @@ import {
20
20
  import type { TableOptions } from '../../../nodeviews/types';
21
21
 
22
22
  import { hasTableBeenResized } from './colgroup';
23
- import { MAX_SCALING_PERCENT } from './consts';
23
+ import {
24
+ MAX_SCALING_PERCENT,
25
+ MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION,
26
+ } from './consts';
24
27
 
25
28
  // Translates named layouts in number values.
26
29
  export function getLayoutSize(
@@ -137,19 +140,35 @@ export const getTableContainerElementWidth = (table: PMNode) => {
137
140
  return getTableContainerWidth(table);
138
141
  };
139
142
 
140
- export const getTableScalingPercent = (table: PMNode, tableRef: HTMLElement | null) => {
143
+ export const getTableScalingPercent = (
144
+ table: PMNode,
145
+ tableRef: HTMLElement | null,
146
+ shouldUseIncreasedScalingPercent?: boolean,
147
+ ) => {
148
+ const maxScalingPercent = shouldUseIncreasedScalingPercent
149
+ ? MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION
150
+ : MAX_SCALING_PERCENT;
151
+
141
152
  const tableWidth = getTableContainerElementWidth(table);
142
153
  let renderWidth = tableRef?.parentElement?.clientWidth || tableWidth;
143
154
  // minus 1 here to avoid any 1px scroll in Firefox
144
155
  let scalePercent = (renderWidth - 1) / tableWidth;
145
- scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
156
+ scalePercent = Math.max(scalePercent, 1 - maxScalingPercent);
146
157
  return Math.min(scalePercent, 1);
147
158
  };
148
159
 
149
- export const getStaticTableScalingPercent = (table: PMNode, tableRenderWidth: number) => {
160
+ export const getStaticTableScalingPercent = (
161
+ table: PMNode,
162
+ tableRenderWidth: number,
163
+ shouldUseIncreasedScalingPercent?: boolean,
164
+ ) => {
165
+ const maxScalingPercent = shouldUseIncreasedScalingPercent
166
+ ? MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION
167
+ : MAX_SCALING_PERCENT;
168
+
150
169
  const tableWidth = getTableContainerElementWidth(table);
151
170
  // minus 1 here to avoid any 1px scroll in Firefox
152
171
  let scalePercent = (tableRenderWidth - 1) / tableWidth;
153
- scalePercent = Math.max(scalePercent, 1 - MAX_SCALING_PERCENT);
172
+ scalePercent = Math.max(scalePercent, 1 - maxScalingPercent);
154
173
  return Math.min(scalePercent, 1);
155
174
  };
@@ -16,12 +16,13 @@ export const resizeColumn = (
16
16
  tableNode: PmNode,
17
17
  selectedColumns?: number[],
18
18
  isTableScalingEnabled = false,
19
+ shouldUseIncreasedScalingPercent = false,
19
20
  ): ResizeState => {
20
21
  let scalePercent = 1;
21
22
  let resizeAmount = amount;
22
23
 
23
24
  if (isTableScalingEnabled) {
24
- scalePercent = getTableScalingPercent(tableNode, tableRef);
25
+ scalePercent = getTableScalingPercent(tableNode, tableRef, shouldUseIncreasedScalingPercent);
25
26
  resizeAmount = amount / scalePercent;
26
27
  }
27
28
 
@@ -32,7 +33,13 @@ export const resizeColumn = (
32
33
  ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns)
33
34
  : resizeState;
34
35
 
35
- updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
36
+ updateColgroup(
37
+ newState,
38
+ tableRef,
39
+ tableNode,
40
+ isTableScalingEnabled,
41
+ shouldUseIncreasedScalingPercent,
42
+ );
36
43
 
37
44
  return newState;
38
45
  };
@@ -47,13 +54,13 @@ export const resizeColumnAndTable = (
47
54
  selectedColumns?: number[],
48
55
  isTableScalingEnabled = false,
49
56
  originalTableWidth?: number,
57
+ shouldUseIncreasedScalingPercent = false,
50
58
  ): ResizeState => {
51
59
  // TODO: can we use document state, and apply scaling factor?
52
60
  const tableWidth = tableRef.clientWidth;
53
61
  const tableContainerWidth = tableRef.closest('.pm-table-container')?.clientWidth;
54
62
 
55
63
  const isOverflowed = !!(tableWidth && tableContainerWidth && tableWidth > tableContainerWidth);
56
-
57
64
  let resizeAmount = amount * 2;
58
65
 
59
66
  // todo: reimplement - use getTableScalingPercentFrozen to get scaled percent before table width changes dynamically
@@ -84,7 +91,7 @@ export const resizeColumnAndTable = (
84
91
 
85
92
  // this function only updates the colgroup in DOM, it reverses the scalePercent
86
93
  // todo: change isScalingEnabled to true when reimplementing scaling
87
- updateColgroup(newState, tableRef, tableNode, false);
94
+ updateColgroup(newState, tableRef, tableNode, false, shouldUseIncreasedScalingPercent);
88
95
 
89
96
  // use the difference in width from affected column to update overall table width
90
97
  const delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
@@ -24,6 +24,7 @@ export const getResizeState = ({
24
24
  start,
25
25
  domAtPos,
26
26
  isTableScalingEnabled = false,
27
+ shouldUseIncreasedScalingPercent = false,
27
28
  }: {
28
29
  minWidth: number;
29
30
  maxSize: number;
@@ -32,9 +33,10 @@ export const getResizeState = ({
32
33
  start: number;
33
34
  domAtPos: (pos: number) => { node: Node; offset: number };
34
35
  isTableScalingEnabled: boolean;
36
+ shouldUseIncreasedScalingPercent: boolean;
35
37
  }): ResizeState => {
36
38
  if (isTableScalingEnabled) {
37
- const scalePercent = getTableScalingPercent(table, tableRef);
39
+ const scalePercent = getTableScalingPercent(table, tableRef, shouldUseIncreasedScalingPercent);
38
40
  minWidth = Math.ceil(minWidth / scalePercent);
39
41
  }
40
42
  // If the table has been resized, we can use the column widths from the table node
@@ -67,6 +69,7 @@ export const getResizeState = ({
67
69
  table,
68
70
  isTableScalingEnabled,
69
71
  shouldReinsertColgroup, // don't reinsert colgroup when preserving table width - this causes widths to jump
72
+ shouldUseIncreasedScalingPercent,
70
73
  );
71
74
  const cols = Array.from(colgroupChildren).map((_, index) => {
72
75
  // If the table hasn't been resized and we have a table width attribute, we can use it
@@ -104,6 +107,7 @@ export const updateColgroup = (
104
107
  tableRef: HTMLElement | null,
105
108
  tableNode?: PMNode,
106
109
  isTableScalingEnabled?: boolean,
110
+ shouldUseIncreasedScalingPercent?: boolean,
107
111
  ): void => {
108
112
  const cols = tableRef?.querySelectorAll('col');
109
113
  const columnsCount = cols?.length;
@@ -113,7 +117,11 @@ export const updateColgroup = (
113
117
  We need to remove !isColumnResizing if we handled auto scale table when mouseUp event.
114
118
  * */
115
119
  if (isTableScalingEnabled && tableNode) {
116
- const scalePercent = getTableScalingPercent(tableNode, tableRef);
120
+ const scalePercent = getTableScalingPercent(
121
+ tableNode,
122
+ tableRef,
123
+ shouldUseIncreasedScalingPercent,
124
+ );
117
125
  state.cols
118
126
  .filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
119
127
  .forEach((column, i) => {
@@ -359,10 +367,10 @@ export const getNewResizeStateFromSelectedColumns = (
359
367
  let resizeState;
360
368
 
361
369
  let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
362
- if (
363
- isTableScalingEnabled &&
364
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')
365
- ) {
370
+
371
+ const isTableScalingEnabledWithLockButton =
372
+ isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
373
+ if (isTableScalingEnabledWithLockButton) {
366
374
  isTableScalingEnabledOnCurrentTable = table.node.attrs.displayMode !== 'fixed';
367
375
  }
368
376
 
@@ -374,6 +382,9 @@ export const getNewResizeStateFromSelectedColumns = (
374
382
  start: table.start,
375
383
  domAtPos,
376
384
  isTableScalingEnabled: isTableScalingEnabledOnCurrentTable,
385
+ shouldUseIncreasedScalingPercent:
386
+ isTableScalingEnabledWithLockButton &&
387
+ getBooleanFF('platform.editor.table.use-increased-scaling-percent'),
377
388
  });
378
389
 
379
390
  const newResizeState = evenSelectedColumnsWidths(resizeState, rect);
@@ -40,6 +40,7 @@ export const scale = (
40
40
  options: ScaleOptions,
41
41
  domAtPos: DomAtPos,
42
42
  isTableScalingEnabledOnCurrentTable = false,
43
+ shouldUseIncreasedScalingPercent = false,
43
44
  ): ResizeState | undefined => {
44
45
  const {
45
46
  node,
@@ -89,6 +90,7 @@ export const scale = (
89
90
  start,
90
91
  domAtPos,
91
92
  isTableScalingEnabled: isTableScalingEnabledOnCurrentTable,
93
+ shouldUseIncreasedScalingPercent,
92
94
  });
93
95
 
94
96
  return scaleTableTo(resizeState, newWidth);
@@ -101,6 +103,7 @@ export const scaleWithParent = (
101
103
  start: number,
102
104
  domAtPos: DomAtPos,
103
105
  isTableScalingEnabledOnCurrentTable = false,
106
+ shouldUseIncreasedScalingPercent = false,
104
107
  ) => {
105
108
  const resizeState = getResizeState({
106
109
  minWidth: tableCellMinWidth,
@@ -110,6 +113,7 @@ export const scaleWithParent = (
110
113
  start,
111
114
  domAtPos,
112
115
  isTableScalingEnabled: isTableScalingEnabledOnCurrentTable,
116
+ shouldUseIncreasedScalingPercent,
113
117
  });
114
118
 
115
119
  if (table.attrs.isNumberColumnEnabled) {
@@ -165,10 +169,9 @@ export const previewScaleTable = (
165
169
  }
166
170
 
167
171
  let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
168
- if (
169
- isTableScalingEnabled &&
170
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')
171
- ) {
172
+ const isTableScalingEnabledWithLockButton =
173
+ isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
174
+ if (isTableScalingEnabledWithLockButton) {
172
175
  isTableScalingEnabledOnCurrentTable =
173
176
  isTableScalingEnabled && node.attrs.displayMode !== 'fixed';
174
177
  }
@@ -179,12 +182,24 @@ export const previewScaleTable = (
179
182
  return;
180
183
  }
181
184
 
185
+ const shouldUseIncreasedScalingPercent =
186
+ isTableScalingEnabledWithLockButton &&
187
+ getBooleanFF('platform.editor.table.use-increased-scaling-percent');
188
+
182
189
  const resizeState = parentWidth
183
- ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false) // Here last value is isTableScalingEnabled = false
184
- : scale(tableRef, options, domAtPos, false);
190
+ ? scaleWithParent(
191
+ tableRef,
192
+ parentWidth,
193
+ node,
194
+ start,
195
+ domAtPos,
196
+ false, // Here isTableScalingEnabled = false
197
+ shouldUseIncreasedScalingPercent,
198
+ )
199
+ : scale(tableRef, options, domAtPos, false, shouldUseIncreasedScalingPercent);
185
200
 
186
201
  if (resizeState) {
187
- updateColgroup(resizeState, tableRef, node, false);
202
+ updateColgroup(resizeState, tableRef, node, false, shouldUseIncreasedScalingPercent);
188
203
  }
189
204
  };
190
205
 
@@ -195,6 +210,7 @@ export const scaleTable =
195
210
  options: ScaleOptions,
196
211
  domAtPos: DomAtPos,
197
212
  isTableScalingEnabledOnCurrentTable = false,
213
+ shouldUseIncreasedScalingPercent = false,
198
214
  ) =>
199
215
  (tr: Transaction) => {
200
216
  if (!tableRef) {
@@ -207,7 +223,7 @@ export const scaleTable =
207
223
  // If its not a re-sized table, we still want to re-create cols
208
224
  // To force reflow of columns upon delete.
209
225
  if (!isTableScalingEnabledOnCurrentTable) {
210
- insertColgroupFromNode(tableRef, node);
226
+ insertColgroupFromNode(tableRef, node, false, undefined, shouldUseIncreasedScalingPercent);
211
227
  }
212
228
  tr.setMeta('scrollIntoView', false);
213
229
  return tr;
@@ -222,9 +238,16 @@ export const scaleTable =
222
238
  start,
223
239
  domAtPos,
224
240
  isTableScalingEnabledOnCurrentTable,
241
+ shouldUseIncreasedScalingPercent,
225
242
  );
226
243
  } else {
227
- resizeState = scale(tableRef, options, domAtPos, isTableScalingEnabledOnCurrentTable);
244
+ resizeState = scale(
245
+ tableRef,
246
+ options,
247
+ domAtPos,
248
+ isTableScalingEnabledOnCurrentTable,
249
+ shouldUseIncreasedScalingPercent,
250
+ );
228
251
  }
229
252
 
230
253
  if (resizeState) {
package/src/toolbar.tsx CHANGED
@@ -6,6 +6,7 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
6
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
7
  import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
8
8
  import commonMessages, { tableMessages as messages } from '@atlaskit/editor-common/messages';
9
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
9
10
  import type { typeOption } from '@atlaskit/editor-common/src/types/floating-toolbar';
10
11
  import type {
11
12
  Command,
@@ -179,6 +180,7 @@ export const getToolbarCellOptionsConfig = (
179
180
  getEditorContainerWidth: GetEditorContainerWidth,
180
181
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
181
182
  isTableScalingEnabled = false,
183
+ shouldUseIncreasedScalingPercent = false,
182
184
  ): FloatingToolbarDropdown<Command> => {
183
185
  const { top, bottom, right, left } = initialSelectionRect;
184
186
  const numberOfColumns = right - left;
@@ -193,10 +195,11 @@ export const getToolbarCellOptionsConfig = (
193
195
  const selectionRect = getClosestSelectionRect(state);
194
196
  const index = selectionRect?.right;
195
197
  if (index) {
196
- insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(
197
- INPUT_METHOD.FLOATING_TB,
198
- index,
199
- )(state, dispatch, view);
198
+ insertColumnWithAnalytics(
199
+ editorAnalyticsAPI,
200
+ isTableScalingEnabled,
201
+ shouldUseIncreasedScalingPercent,
202
+ )(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
200
203
  }
201
204
  return true;
202
205
  },
@@ -230,11 +233,11 @@ export const getToolbarCellOptionsConfig = (
230
233
  onClick: (state: EditorState, dispatch?: CommandDispatch, view?: EditorView) => {
231
234
  const selectionRect = getClosestSelectionRect(state);
232
235
  if (selectionRect) {
233
- deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, selectionRect)(
234
- state,
235
- dispatch,
236
- view,
237
- );
236
+ deleteColumnsWithAnalytics(
237
+ editorAnalyticsAPI,
238
+ isTableScalingEnabled,
239
+ shouldUseIncreasedScalingPercent,
240
+ )(INPUT_METHOD.FLOATING_TB, selectionRect)(state, dispatch, view);
238
241
  }
239
242
  return true;
240
243
  },
@@ -431,6 +434,7 @@ export const getToolbarConfig =
431
434
  getEditorFeatureFlags: GetEditorFeatureFlags,
432
435
  getEditorView: () => EditorView | null,
433
436
  options?: TablePluginOptions,
437
+ shouldUseIncreasedScalingPercent = false,
434
438
  ) =>
435
439
  (config: PluginConfig): FloatingToolbarHandler =>
436
440
  (state, intl) => {
@@ -464,6 +468,7 @@ export const getToolbarConfig =
464
468
  getEditorContainerWidth,
465
469
  editorAnalyticsAPI,
466
470
  options?.isTableScalingEnabled,
471
+ shouldUseIncreasedScalingPercent,
467
472
  );
468
473
 
469
474
  let columnSettingsItems;
@@ -588,6 +593,7 @@ const getCellItems = (
588
593
  getEditorContainerWidth: GetEditorContainerWidth,
589
594
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
590
595
  isTableScalingEnabled = false,
596
+ shouldUseIncreasedScalingPercent = false,
591
597
  ): Array<FloatingToolbarItem<Command>> => {
592
598
  const initialSelectionRect = getClosestSelectionRect(state);
593
599
  if (initialSelectionRect) {
@@ -599,6 +605,7 @@ const getCellItems = (
599
605
  getEditorContainerWidth,
600
606
  editorAnalyticsAPI,
601
607
  isTableScalingEnabled,
608
+ shouldUseIncreasedScalingPercent,
602
609
  );
603
610
  return [cellOptions, separator(cellOptions.hidden!)];
604
611
  }
@@ -910,8 +917,9 @@ export const isLayoutOptionDisabled = (
910
917
  getEditorContainerWidth: GetEditorContainerWidth,
911
918
  ) => {
912
919
  const lineLength = getEditorContainerWidth().lineLength;
920
+ const tableWidth = getTableContainerWidth(selectedNode);
913
921
 
914
- if (selectedNode && lineLength && selectedNode.attrs.width > lineLength) {
922
+ if (selectedNode && lineLength && tableWidth > lineLength) {
915
923
  return true;
916
924
  }
917
925
 
@@ -104,7 +104,7 @@ export const updateColumnWidths =
104
104
  * @returns Updated transaction with rescaled columns for a given table
105
105
  */
106
106
  export const rescaleColumns =
107
- (isTableScalingEnabled = false) =>
107
+ (isTableScalingEnabled = false, shouldUseIncreasedScalingPercent = false) =>
108
108
  (table: ContentNodeWithPos, view: EditorView | undefined) =>
109
109
  (tr: Transaction): Transaction => {
110
110
  if (!view) {
@@ -206,6 +206,7 @@ export const rescaleColumns =
206
206
  domAtPos,
207
207
  maxSize: previousTableInfo.possibleMaxWidth,
208
208
  isTableScalingEnabled: shouldScale,
209
+ shouldUseIncreasedScalingPercent,
209
210
  });
210
211
 
211
212
  // Two scenarios that require scaling: