@atlaskit/editor-plugin-table 7.16.17 → 7.16.19

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 (134) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/commands/column-resize.js +4 -3
  3. package/dist/cjs/commands/delete.js +3 -2
  4. package/dist/cjs/commands/insert.js +12 -8
  5. package/dist/cjs/commands-with-analytics.js +10 -7
  6. package/dist/cjs/event-handlers.js +3 -2
  7. package/dist/cjs/nodeviews/TableComponent.js +32 -19
  8. package/dist/cjs/nodeviews/TableContainer.js +4 -0
  9. package/dist/cjs/nodeviews/TableResizer.js +8 -7
  10. package/dist/cjs/nodeviews/table.js +6 -4
  11. package/dist/cjs/plugin.js +9 -6
  12. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +12 -13
  13. package/dist/cjs/pm-plugins/keymap.js +11 -9
  14. package/dist/cjs/pm-plugins/main.js +4 -1
  15. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +10 -9
  16. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +4 -3
  17. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +4 -3
  18. package/dist/cjs/toolbar.js +54 -37
  19. package/dist/cjs/transforms/column-width.js +3 -3
  20. package/dist/cjs/transforms/delete-columns.js +3 -2
  21. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +21 -15
  22. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +3 -2
  23. package/dist/cjs/ui/FloatingDragMenu/index.js +6 -3
  24. package/dist/cjs/ui/FloatingInsertButton/index.js +7 -8
  25. package/dist/cjs/utils/drag-menu.js +5 -4
  26. package/dist/es2019/commands/column-resize.js +4 -3
  27. package/dist/es2019/commands/delete.js +2 -2
  28. package/dist/es2019/commands/insert.js +8 -8
  29. package/dist/es2019/commands-with-analytics.js +9 -8
  30. package/dist/es2019/event-handlers.js +2 -2
  31. package/dist/es2019/nodeviews/TableComponent.js +28 -17
  32. package/dist/es2019/nodeviews/TableContainer.js +4 -0
  33. package/dist/es2019/nodeviews/TableResizer.js +9 -8
  34. package/dist/es2019/nodeviews/table.js +5 -4
  35. package/dist/es2019/plugin.js +9 -6
  36. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +7 -10
  37. package/dist/es2019/pm-plugins/keymap.js +9 -9
  38. package/dist/es2019/pm-plugins/main.js +4 -1
  39. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +10 -9
  40. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +4 -4
  41. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +4 -4
  42. package/dist/es2019/toolbar.js +51 -39
  43. package/dist/es2019/transforms/column-width.js +2 -3
  44. package/dist/es2019/transforms/delete-columns.js +2 -2
  45. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +12 -7
  46. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +3 -2
  47. package/dist/es2019/ui/FloatingDragMenu/index.js +5 -3
  48. package/dist/es2019/ui/FloatingInsertButton/index.js +6 -8
  49. package/dist/es2019/utils/drag-menu.js +4 -4
  50. package/dist/esm/commands/column-resize.js +4 -3
  51. package/dist/esm/commands/delete.js +3 -2
  52. package/dist/esm/commands/insert.js +12 -8
  53. package/dist/esm/commands-with-analytics.js +10 -7
  54. package/dist/esm/event-handlers.js +3 -2
  55. package/dist/esm/nodeviews/TableComponent.js +32 -19
  56. package/dist/esm/nodeviews/TableContainer.js +4 -0
  57. package/dist/esm/nodeviews/TableResizer.js +9 -8
  58. package/dist/esm/nodeviews/table.js +6 -4
  59. package/dist/esm/plugin.js +9 -6
  60. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +12 -13
  61. package/dist/esm/pm-plugins/keymap.js +11 -9
  62. package/dist/esm/pm-plugins/main.js +4 -1
  63. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +10 -9
  64. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +4 -3
  65. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +4 -3
  66. package/dist/esm/toolbar.js +54 -37
  67. package/dist/esm/transforms/column-width.js +3 -3
  68. package/dist/esm/transforms/delete-columns.js +3 -2
  69. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +21 -15
  70. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +3 -2
  71. package/dist/esm/ui/FloatingDragMenu/index.js +6 -3
  72. package/dist/esm/ui/FloatingInsertButton/index.js +7 -8
  73. package/dist/esm/utils/drag-menu.js +5 -4
  74. package/dist/types/commands/column-resize.d.ts +2 -1
  75. package/dist/types/commands/delete.d.ts +1 -1
  76. package/dist/types/commands/insert.d.ts +4 -4
  77. package/dist/types/commands-with-analytics.d.ts +4 -4
  78. package/dist/types/event-handlers.d.ts +1 -1
  79. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  80. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  81. package/dist/types/nodeviews/table.d.ts +1 -0
  82. package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +1 -1
  83. package/dist/types/pm-plugins/keymap.d.ts +1 -1
  84. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +1 -1
  85. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +1 -1
  86. package/dist/types/toolbar.d.ts +5 -5
  87. package/dist/types/transforms/column-width.d.ts +1 -1
  88. package/dist/types/transforms/delete-columns.d.ts +1 -1
  89. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  90. package/dist/types/ui/FloatingInsertButton/index.d.ts +1 -0
  91. package/dist/types/utils/drag-menu.d.ts +1 -1
  92. package/dist/types-ts4.5/commands/column-resize.d.ts +2 -1
  93. package/dist/types-ts4.5/commands/delete.d.ts +1 -1
  94. package/dist/types-ts4.5/commands/insert.d.ts +4 -4
  95. package/dist/types-ts4.5/commands-with-analytics.d.ts +4 -4
  96. package/dist/types-ts4.5/event-handlers.d.ts +1 -1
  97. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  98. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  99. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -0
  100. package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +1 -1
  101. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +1 -1
  102. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +1 -1
  103. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +1 -1
  104. package/dist/types-ts4.5/toolbar.d.ts +5 -5
  105. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
  106. package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
  107. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -1
  108. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +1 -0
  109. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  110. package/package.json +5 -8
  111. package/src/commands/column-resize.ts +6 -6
  112. package/src/commands/delete.ts +7 -1
  113. package/src/commands/insert.ts +33 -5
  114. package/src/commands-with-analytics.ts +14 -2
  115. package/src/event-handlers.ts +2 -0
  116. package/src/nodeviews/TableComponent.tsx +28 -28
  117. package/src/nodeviews/TableContainer.tsx +6 -0
  118. package/src/nodeviews/TableResizer.tsx +16 -6
  119. package/src/nodeviews/table.tsx +4 -2
  120. package/src/plugin.tsx +17 -7
  121. package/src/pm-plugins/drag-and-drop/plugin.ts +26 -13
  122. package/src/pm-plugins/keymap.ts +30 -4
  123. package/src/pm-plugins/main.ts +2 -0
  124. package/src/pm-plugins/table-resizing/event-handlers.ts +12 -14
  125. package/src/pm-plugins/table-resizing/utils/resize-state.ts +5 -5
  126. package/src/pm-plugins/table-resizing/utils/scale-table.ts +6 -4
  127. package/src/toolbar.tsx +97 -40
  128. package/src/transforms/column-width.ts +7 -3
  129. package/src/transforms/delete-columns.ts +6 -2
  130. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +12 -4
  131. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -0
  132. package/src/ui/FloatingDragMenu/index.tsx +4 -4
  133. package/src/ui/FloatingInsertButton/index.tsx +12 -9
  134. package/src/utils/drag-menu.ts +13 -4
@@ -29,7 +29,12 @@ import { createPluginState, getPluginState } from './plugin-factory';
29
29
  import { pluginKey } from './plugin-key';
30
30
  import { getDraggableDataFromEvent } from './utils/monitor';
31
31
 
32
- const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
32
+ const destroyFn = (
33
+ editorView: EditorView,
34
+ editorAnalyticsAPI: any,
35
+ isTableScalingEnabled: boolean,
36
+ isTableFixedColumnWidthsOptionEnabled: boolean,
37
+ ) => {
33
38
  const editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
34
39
 
35
40
  const rowAutoScrollers = editorPageScrollContainer
@@ -211,24 +216,22 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
211
216
  if (sourceType === 'table-column') {
212
217
  const { tableRef, tableNode } = getTablePluginState(editorView.state);
213
218
  if (tableRef && tableNode) {
214
- const { isTableScalingEnabled = false } = getTablePluginState(editorView.state);
215
-
216
219
  let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
217
- const isTableScalingEnabledWithLockButton =
218
- isTableScalingEnabled &&
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) {
220
+ const isTableScalingWithFixedColumnWidthsOptionEnabled =
221
+ isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled;
222
+ if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
225
223
  isTableScalingEnabledOnCurrentTable = tableNode.attrs.displayMode !== 'fixed';
226
224
  }
227
225
 
226
+ const shouldUseIncreasedScalingPercent =
227
+ isTableScalingWithFixedColumnWidthsOptionEnabled &&
228
+ getBooleanFF('platform.editor.table.use-increased-scaling-percent');
229
+
228
230
  insertColgroupFromNode(
229
231
  tableRef,
230
232
  tableNode,
231
233
  isTableScalingEnabledOnCurrentTable,
234
+ undefined,
232
235
  shouldUseIncreasedScalingPercent,
233
236
  );
234
237
  }
@@ -241,7 +244,12 @@ const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
241
244
  );
242
245
  };
243
246
 
244
- export const createPlugin = (dispatch: Dispatch, editorAnalyticsAPI?: EditorAnalyticsAPI) => {
247
+ export const createPlugin = (
248
+ dispatch: Dispatch,
249
+ editorAnalyticsAPI?: EditorAnalyticsAPI,
250
+ isTableScalingEnabled = false,
251
+ isTableFixedColumnWidthsOptionEnabled = false,
252
+ ) => {
245
253
  return new SafePlugin({
246
254
  state: createPluginState(dispatch, (state) => ({
247
255
  decorationSet: DecorationSet.empty,
@@ -310,7 +318,12 @@ export const createPlugin = (dispatch: Dispatch, editorAnalyticsAPI?: EditorAnal
310
318
  },
311
319
  view: (editorView: EditorView) => {
312
320
  return {
313
- destroy: destroyFn(editorView, editorAnalyticsAPI),
321
+ destroy: destroyFn(
322
+ editorView,
323
+ editorAnalyticsAPI,
324
+ isTableScalingEnabled,
325
+ isTableFixedColumnWidthsOptionEnabled,
326
+ ),
314
327
  };
315
328
  },
316
329
  props: {
@@ -65,6 +65,8 @@ export function keymapPlugin(
65
65
  isFullWidthEnabled?: boolean,
66
66
  pluginInjectionApi?: PluginInjectionAPIWithA11y,
67
67
  getIntl?: () => IntlShape,
68
+ isCellBackgroundDuplicated = false,
69
+ isTableFixedColumnWidthsOptionEnabled = false,
68
70
  shouldUseIncreasedScalingPercent?: boolean,
69
71
  ): SafePlugin {
70
72
  const list = {};
@@ -116,13 +118,23 @@ export function keymapPlugin(
116
118
 
117
119
  bindKeymapWithCommand(
118
120
  addColumnBefore.common!,
119
- addColumnBeforeCommand(isTableScalingEnabled, shouldUseIncreasedScalingPercent),
121
+ addColumnBeforeCommand(
122
+ isTableScalingEnabled,
123
+ isCellBackgroundDuplicated,
124
+ isTableFixedColumnWidthsOptionEnabled,
125
+ shouldUseIncreasedScalingPercent,
126
+ ),
120
127
  list,
121
128
  );
122
129
 
123
130
  bindKeymapWithCommand(
124
131
  addColumnAfter.common!,
125
- addColumnAfterCommand(isTableScalingEnabled, shouldUseIncreasedScalingPercent),
132
+ addColumnAfterCommand(
133
+ isTableScalingEnabled,
134
+ isCellBackgroundDuplicated,
135
+ isTableFixedColumnWidthsOptionEnabled,
136
+ shouldUseIncreasedScalingPercent,
137
+ ),
126
138
  list,
127
139
  );
128
140
 
@@ -141,13 +153,23 @@ export function keymapPlugin(
141
153
 
142
154
  bindKeymapWithCommand(
143
155
  addColumnBeforeVO.common!,
144
- addColumnBeforeCommand(isTableScalingEnabled),
156
+ addColumnBeforeCommand(
157
+ isTableScalingEnabled,
158
+ isCellBackgroundDuplicated,
159
+ isTableFixedColumnWidthsOptionEnabled,
160
+ shouldUseIncreasedScalingPercent,
161
+ ),
145
162
  list,
146
163
  );
147
164
 
148
165
  bindKeymapWithCommand(
149
166
  addColumnAfterVO.common!,
150
- addColumnAfterCommand(isTableScalingEnabled),
167
+ addColumnAfterCommand(
168
+ isTableScalingEnabled,
169
+ isCellBackgroundDuplicated,
170
+ isTableFixedColumnWidthsOptionEnabled,
171
+ shouldUseIncreasedScalingPercent,
172
+ ),
151
173
  list,
152
174
  );
153
175
  }
@@ -191,6 +213,7 @@ export function keymapPlugin(
191
213
  deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(
192
214
  editorAnalyticsAPI,
193
215
  isTableScalingEnabled,
216
+ isTableFixedColumnWidthsOptionEnabled,
194
217
  shouldUseIncreasedScalingPercent,
195
218
  ),
196
219
  list,
@@ -201,6 +224,7 @@ export function keymapPlugin(
201
224
  deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(
202
225
  editorAnalyticsAPI,
203
226
  isTableScalingEnabled,
227
+ isTableFixedColumnWidthsOptionEnabled,
204
228
  shouldUseIncreasedScalingPercent,
205
229
  ),
206
230
  list,
@@ -243,6 +267,7 @@ export function keymapPlugin(
243
267
  -10,
244
268
  getEditorContainerWidth,
245
269
  isTableScalingEnabled,
270
+ isTableFixedColumnWidthsOptionEnabled,
246
271
  INPUT_METHOD.SHORTCUT,
247
272
  ariaNotifyPlugin,
248
273
  getIntl,
@@ -256,6 +281,7 @@ export function keymapPlugin(
256
281
  10,
257
282
  getEditorContainerWidth,
258
283
  isTableScalingEnabled,
284
+ isTableFixedColumnWidthsOptionEnabled,
259
285
  INPUT_METHOD.SHORTCUT,
260
286
  ariaNotifyPlugin,
261
287
  getIntl,
@@ -158,6 +158,7 @@ export const createPlugin = (
158
158
  }
159
159
 
160
160
  if (tr) {
161
+ const { tableWithFixedColumnWidthsOption = false } = getEditorFeatureFlags();
161
162
  // "fixTables" removes empty rows as we don't allow that in schema
162
163
  const updatedTr = handleCut(
163
164
  tr,
@@ -166,6 +167,7 @@ export const createPlugin = (
166
167
  editorAnalyticsAPI,
167
168
  editorViewRef || undefined,
168
169
  isTableScalingEnabled,
170
+ tableWithFixedColumnWidthsOption,
169
171
  shouldUseIncreasedScalingPercent,
170
172
  );
171
173
  return fixTables(updatedTr) || updatedTr;
@@ -84,10 +84,12 @@ export const handleMouseDown = (
84
84
  });
85
85
 
86
86
  let shouldScale = tableDepth === 0 && isTableScalingEnabled;
87
+ const { tableWithFixedColumnWidthsOption = false } = getEditorFeatureFlags();
87
88
 
88
- const isTableScalingEnabledWithLockButton =
89
- isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
90
- if (isTableScalingEnabledWithLockButton) {
89
+ const isTableScalingWithFixedColumnWidthsOptionEnabled =
90
+ isTableScalingEnabled && tableWithFixedColumnWidthsOption;
91
+
92
+ if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
91
93
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
92
94
  }
93
95
 
@@ -100,7 +102,7 @@ export const handleMouseDown = (
100
102
  domAtPos,
101
103
  isTableScalingEnabled: shouldScale,
102
104
  shouldUseIncreasedScalingPercent:
103
- isTableScalingEnabledWithLockButton &&
105
+ isTableScalingWithFixedColumnWidthsOptionEnabled &&
104
106
  getBooleanFF('platform.editor.table.use-increased-scaling-percent'),
105
107
  });
106
108
 
@@ -183,10 +185,8 @@ export const handleMouseDown = (
183
185
  selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
184
186
 
185
187
  let shouldScale = tableDepth === 0 && isTableScalingEnabled;
186
- const isTableScalingEnabledWithLockButton =
187
- isTableScalingEnabled &&
188
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
189
- if (isTableScalingEnabledWithLockButton) {
188
+
189
+ if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
190
190
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
191
191
  }
192
192
 
@@ -213,7 +213,7 @@ export const handleMouseDown = (
213
213
  originalTable,
214
214
  resizingSelectedColumns ? selectedColumns : undefined,
215
215
  shouldScale,
216
- isTableScalingEnabledWithLockButton &&
216
+ isTableScalingWithFixedColumnWidthsOptionEnabled &&
217
217
  getBooleanFF('platform.editor.table.use-increased-scaling-percent'),
218
218
  );
219
219
  tr = updateColumnWidths(newResizeState, table, start)(tr);
@@ -289,13 +289,11 @@ export const handleMouseDown = (
289
289
  const colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter!.attrs.colspan - 1;
290
290
 
291
291
  let shouldScale = tableDepth === 0 && isTableScalingEnabled;
292
- const isTableScalingEnabledWithLockButton =
293
- isTableScalingEnabled &&
294
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
292
+
295
293
  const shouldUseIncreasedScalingPercent =
296
- isTableScalingEnabledWithLockButton &&
294
+ isTableScalingWithFixedColumnWidthsOptionEnabled &&
297
295
  getBooleanFF('platform.editor.table.use-increased-scaling-percent');
298
- if (isTableScalingEnabledWithLockButton) {
296
+ if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
299
297
  shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
300
298
  }
301
299
 
@@ -325,6 +325,7 @@ export const getNewResizeStateFromSelectedColumns = (
325
325
  domAtPos: (pos: number) => { node: Node; offset: number },
326
326
  getEditorContainerWidth: GetEditorContainerWidth,
327
327
  isTableScalingEnabled = false,
328
+ isTableFixedColumnWidthsOptionEnabled = false,
328
329
  ): ResizeStateWithAnalytics | undefined => {
329
330
  // Fail early so that we don't do complex calculations for no reason
330
331
  const numColumnsSelected = rect.right - rect.left;
@@ -367,10 +368,9 @@ export const getNewResizeStateFromSelectedColumns = (
367
368
  let resizeState;
368
369
 
369
370
  let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
370
-
371
- const isTableScalingEnabledWithLockButton =
372
- isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
373
- if (isTableScalingEnabledWithLockButton) {
371
+ const isTableScalingWithFixedColumnWidthsOptionEnabled =
372
+ isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled;
373
+ if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
374
374
  isTableScalingEnabledOnCurrentTable = table.node.attrs.displayMode !== 'fixed';
375
375
  }
376
376
 
@@ -383,7 +383,7 @@ export const getNewResizeStateFromSelectedColumns = (
383
383
  domAtPos,
384
384
  isTableScalingEnabled: isTableScalingEnabledOnCurrentTable,
385
385
  shouldUseIncreasedScalingPercent:
386
- isTableScalingEnabledWithLockButton &&
386
+ isTableScalingWithFixedColumnWidthsOptionEnabled &&
387
387
  getBooleanFF('platform.editor.table.use-increased-scaling-percent'),
388
388
  });
389
389
 
@@ -153,6 +153,7 @@ export const previewScaleTable = (
153
153
  options: ScaleOptions,
154
154
  domAtPos: DomAtPos,
155
155
  isTableScalingEnabled: boolean = false,
156
+ isTableWithFixedColumnWidthsOptionEnabled: boolean = false,
156
157
  ) => {
157
158
  const { node, start, parentWidth } = options;
158
159
 
@@ -169,9 +170,10 @@ export const previewScaleTable = (
169
170
  }
170
171
 
171
172
  let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
172
- const isTableScalingEnabledWithLockButton =
173
- isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
174
- if (isTableScalingEnabledWithLockButton) {
173
+ const isTableScalingWithFixedColumnWidthsOptionEnabled =
174
+ isTableScalingEnabled && isTableWithFixedColumnWidthsOptionEnabled;
175
+
176
+ if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
175
177
  isTableScalingEnabledOnCurrentTable =
176
178
  isTableScalingEnabled && node.attrs.displayMode !== 'fixed';
177
179
  }
@@ -183,7 +185,7 @@ export const previewScaleTable = (
183
185
  }
184
186
 
185
187
  const shouldUseIncreasedScalingPercent =
186
- isTableScalingEnabledWithLockButton &&
188
+ isTableScalingWithFixedColumnWidthsOptionEnabled &&
187
189
  getBooleanFF('platform.editor.table.use-increased-scaling-percent');
188
190
 
189
191
  const resizeState = parentWidth
package/src/toolbar.tsx CHANGED
@@ -78,6 +78,7 @@ import {
78
78
  import type { TablePluginOptions } from './plugin';
79
79
  import { getPluginState } from './pm-plugins/plugin-factory';
80
80
  import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
81
+ import { getStaticTableScalingPercent } from './pm-plugins/table-resizing/utils/misc';
81
82
  import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizing/utils/resize-state';
82
83
  import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
83
84
  import { canMergeCells } from './transforms';
@@ -156,6 +157,9 @@ export const getToolbarMenuConfig = (
156
157
  },
157
158
  ];
158
159
 
160
+ const tableOptionsDropdownWidth = isTableScalingWithFixedColumnWidthsOptionShown
161
+ ? 192
162
+ : undefined;
159
163
  if (state.isDragAndDropEnabled) {
160
164
  return {
161
165
  id: 'editor.table.tableOptions',
@@ -165,7 +169,7 @@ export const getToolbarMenuConfig = (
165
169
  title: formatMessage(messages.tableOptions),
166
170
  hidden: options.every((option) => option.hidden),
167
171
  options,
168
- dropdownWidth: isTableScalingWithFixedColumnWidthsOptionShown ? 192 : undefined,
172
+ dropdownWidth: tableOptionsDropdownWidth,
169
173
  };
170
174
  } else {
171
175
  return {
@@ -175,7 +179,7 @@ export const getToolbarMenuConfig = (
175
179
  title: formatMessage(messages.tableOptions),
176
180
  hidden: options.every((option) => option.hidden),
177
181
  options,
178
- dropdownWidth: isTableScalingWithFixedColumnWidthsOptionShown ? 192 : undefined,
182
+ dropdownWidth: tableOptionsDropdownWidth,
179
183
  };
180
184
  }
181
185
  };
@@ -191,6 +195,8 @@ export const getToolbarCellOptionsConfig = (
191
195
  getEditorContainerWidth: GetEditorContainerWidth,
192
196
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
193
197
  isTableScalingEnabled = false,
198
+ isCellBackgroundDuplicated = false,
199
+ isTableFixedColumnWidthsOptionEnabled = false,
194
200
  shouldUseIncreasedScalingPercent = false,
195
201
  ): FloatingToolbarDropdown<Command> => {
196
202
  const { top, bottom, right, left } = initialSelectionRect;
@@ -209,6 +215,8 @@ export const getToolbarCellOptionsConfig = (
209
215
  insertColumnWithAnalytics(
210
216
  editorAnalyticsAPI,
211
217
  isTableScalingEnabled,
218
+ isCellBackgroundDuplicated,
219
+ isTableFixedColumnWidthsOptionEnabled,
212
220
  shouldUseIncreasedScalingPercent,
213
221
  )(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
214
222
  }
@@ -247,6 +255,7 @@ export const getToolbarCellOptionsConfig = (
247
255
  deleteColumnsWithAnalytics(
248
256
  editorAnalyticsAPI,
249
257
  isTableScalingEnabled,
258
+ isTableFixedColumnWidthsOptionEnabled,
250
259
  shouldUseIncreasedScalingPercent,
251
260
  )(INPUT_METHOD.FLOATING_TB, selectionRect)(state, dispatch, view);
252
261
  }
@@ -306,6 +315,7 @@ export const getToolbarCellOptionsConfig = (
306
315
  editorView.domAtPos.bind(editorView),
307
316
  getEditorContainerWidth,
308
317
  isTableScalingEnabled,
318
+ isTableFixedColumnWidthsOptionEnabled,
309
319
  )
310
320
  : undefined;
311
321
  const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
@@ -445,7 +455,7 @@ export const getToolbarConfig =
445
455
  getEditorFeatureFlags: GetEditorFeatureFlags,
446
456
  getEditorView: () => EditorView | null,
447
457
  options?: TablePluginOptions,
448
- isTableScalingWithFixedColumnWidthsOptionEnabled = false,
458
+ isTableFixedColumnWidthsOptionEnabled = false,
449
459
  shouldUseIncreasedScalingPercent = false,
450
460
  ) =>
451
461
  (config: PluginConfig): FloatingToolbarHandler =>
@@ -454,6 +464,7 @@ export const getToolbarConfig =
454
464
  const pluginState = getPluginState(state);
455
465
  const resizeState = tableResizingPluginKey.getState(state);
456
466
  const tableWidthState = tableWidthPluginKey.getState(state);
467
+ const isTableScalingEnabled = options?.isTableScalingEnabled || false;
457
468
 
458
469
  // We don't want to show floating toolbar while resizing the table
459
470
  const isWidthResizing = tableWidthState?.resizing;
@@ -462,8 +473,25 @@ export const getToolbarConfig =
462
473
  const nodeType = state.schema.nodes.table;
463
474
  const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
464
475
  const isTableScalingWithFixedColumnWidthsOptionShown =
465
- isTableScalingWithFixedColumnWidthsOptionEnabled && !isNested;
476
+ isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && !isNested;
466
477
  const areTableColumWidthsFixed = tableObject.node.attrs.displayMode === 'fixed';
478
+ const editorView = getEditorView();
479
+
480
+ const getDomRef = (editorView: EditorView) => {
481
+ let element: HTMLElement | undefined;
482
+ const domAtPos = editorView.domAtPos.bind(editorView);
483
+ const parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
484
+ if (parent) {
485
+ const tableRef =
486
+ (parent as HTMLElement).querySelector<HTMLTableElement>('table') || undefined;
487
+ if (tableRef) {
488
+ element =
489
+ closestElement(tableRef, `.${TableCssClassName.TABLE_NODE_WRAPPER}`) || undefined;
490
+ }
491
+ }
492
+
493
+ return element;
494
+ };
467
495
 
468
496
  const menu = getToolbarMenuConfig(
469
497
  config,
@@ -474,34 +502,45 @@ export const getToolbarConfig =
474
502
  areTableColumWidthsFixed,
475
503
  );
476
504
 
477
- let alignmentMenu: Array<FloatingToolbarItem<Command>>;
478
- alignmentMenu =
505
+ const alignmentMenu =
479
506
  options?.isTableAlignmentEnabled && !isNested
480
- ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI, getEditorContainerWidth)
507
+ ? getAlignmentOptionsConfig(
508
+ state,
509
+ intl,
510
+ editorAnalyticsAPI,
511
+ getEditorContainerWidth,
512
+ getDomRef,
513
+ editorView,
514
+ shouldUseIncreasedScalingPercent,
515
+ )
481
516
  : [];
482
517
 
483
- let cellItems: Array<FloatingToolbarItem<Command>>;
484
- cellItems = pluginState.isDragAndDropEnabled
518
+ const isCellBackgroundDuplicated =
519
+ getEditorFeatureFlags().tableDuplicateCellColouring || false;
520
+
521
+ const cellItems = pluginState.isDragAndDropEnabled
485
522
  ? []
486
523
  : getCellItems(
487
524
  state,
488
- getEditorView(),
525
+ editorView,
489
526
  intl,
490
527
  getEditorContainerWidth,
491
528
  editorAnalyticsAPI,
492
- options?.isTableScalingEnabled,
529
+ isTableScalingEnabled,
530
+ isCellBackgroundDuplicated,
531
+ isTableFixedColumnWidthsOptionEnabled,
493
532
  shouldUseIncreasedScalingPercent,
494
533
  );
495
534
 
496
- let columnSettingsItems;
497
- columnSettingsItems = pluginState.isDragAndDropEnabled
535
+ const columnSettingsItems = pluginState.isDragAndDropEnabled
498
536
  ? getColumnSettingItems(
499
537
  state,
500
- getEditorView(),
538
+ editorView,
501
539
  intl,
502
540
  getEditorContainerWidth,
503
541
  editorAnalyticsAPI,
504
- options?.isTableScalingEnabled,
542
+ isTableScalingEnabled,
543
+ isTableFixedColumnWidthsOptionEnabled,
505
544
  )
506
545
  : [];
507
546
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI, getEditorView);
@@ -526,22 +565,6 @@ export const getToolbarConfig =
526
565
  });
527
566
  }
528
567
 
529
- const getDomRef = (editorView: EditorView) => {
530
- let element: HTMLElement | undefined;
531
- const domAtPos = editorView.domAtPos.bind(editorView);
532
- const parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
533
- if (parent) {
534
- const tableRef =
535
- (parent as HTMLElement).querySelector<HTMLTableElement>('table') || undefined;
536
- if (tableRef) {
537
- element =
538
- closestElement(tableRef, `.${TableCssClassName.TABLE_NODE_WRAPPER}`) || undefined;
539
- }
540
- }
541
-
542
- return element;
543
- };
544
-
545
568
  const { stickyScrollbar } = getEditorFeatureFlags();
546
569
 
547
570
  return {
@@ -615,6 +638,8 @@ const getCellItems = (
615
638
  getEditorContainerWidth: GetEditorContainerWidth,
616
639
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
617
640
  isTableScalingEnabled = false,
641
+ isCellBackgroundDuplicated = false,
642
+ isTableFixedColumnWidthsOptionEnabled = false,
618
643
  shouldUseIncreasedScalingPercent = false,
619
644
  ): Array<FloatingToolbarItem<Command>> => {
620
645
  const initialSelectionRect = getClosestSelectionRect(state);
@@ -627,6 +652,8 @@ const getCellItems = (
627
652
  getEditorContainerWidth,
628
653
  editorAnalyticsAPI,
629
654
  isTableScalingEnabled,
655
+ isCellBackgroundDuplicated,
656
+ isTableFixedColumnWidthsOptionEnabled,
630
657
  shouldUseIncreasedScalingPercent,
631
658
  );
632
659
  return [cellOptions, separator(cellOptions.hidden!)];
@@ -639,18 +666,21 @@ export const getDistributeConfig =
639
666
  getEditorContainerWidth: GetEditorContainerWidth,
640
667
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
641
668
  isTableScalingEnabled = false,
669
+ isTableFixedColumnWidthsOptionEnabled = false,
642
670
  ): Command =>
643
671
  (state, dispatch, editorView) => {
644
672
  const selectionOrTableRect = getClosestSelectionOrTableRect(state);
645
673
  if (!editorView || !selectionOrTableRect) {
646
674
  return false;
647
675
  }
676
+
648
677
  const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
649
678
  selectionOrTableRect,
650
679
  state,
651
680
  editorView.domAtPos.bind(editorView),
652
681
  getEditorContainerWidth,
653
682
  isTableScalingEnabled,
683
+ isTableFixedColumnWidthsOptionEnabled,
654
684
  );
655
685
 
656
686
  if (newResizeStateWithAnalytics) {
@@ -672,6 +702,7 @@ const getColumnSettingItems = (
672
702
  getEditorContainerWidth: GetEditorContainerWidth,
673
703
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
674
704
  isTableScalingEnabled = false,
705
+ isTableFixedColumnWidthsOptionEnabled = false,
675
706
  ): Array<FloatingToolbarItem<Command>> => {
676
707
  const pluginState = getPluginState(editorState);
677
708
  const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
@@ -686,6 +717,7 @@ const getColumnSettingItems = (
686
717
  editorView.domAtPos.bind(editorView),
687
718
  getEditorContainerWidth,
688
719
  isTableScalingEnabled,
720
+ isTableFixedColumnWidthsOptionEnabled,
689
721
  );
690
722
 
691
723
  const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
@@ -699,11 +731,12 @@ const getColumnSettingItems = (
699
731
  title: formatMessage(messages.distributeColumns),
700
732
  icon: DistributeColumnIcon,
701
733
  onClick: (state, dispatch, view) =>
702
- getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled)(
703
- state,
704
- dispatch,
705
- view,
706
- ),
734
+ getDistributeConfig(
735
+ getEditorContainerWidth,
736
+ editorAnalyticsAPI,
737
+ isTableScalingEnabled,
738
+ isTableFixedColumnWidthsOptionEnabled,
739
+ )(state, dispatch, view),
707
740
  disabled: !wouldChange,
708
741
  });
709
742
  }
@@ -808,6 +841,9 @@ export const getAlignmentOptionsConfig = (
808
841
  { formatMessage }: ToolbarMenuContext,
809
842
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
810
843
  getEditorContainerWidth: GetEditorContainerWidth,
844
+ getDomRef: (editorView: EditorView) => HTMLElement | undefined,
845
+ editorView: EditorView | null,
846
+ shouldUseIncreasedScalingPercent: boolean,
811
847
  ): Array<FloatingToolbarDropdown<Command>> => {
812
848
  const tableObject = findTable(editorState.selection);
813
849
 
@@ -850,7 +886,13 @@ export const getAlignmentOptionsConfig = (
850
886
  INPUT_METHOD.FLOATING_TB,
851
887
  CHANGE_ALIGNMENT_REASON.TOOLBAR_OPTION_CHANGED,
852
888
  ),
853
- ...(isLayoutOptionDisabled(tableObject.node, getEditorContainerWidth) && {
889
+ ...(isLayoutOptionDisabled(
890
+ tableObject.node,
891
+ getEditorContainerWidth,
892
+ getDomRef,
893
+ editorView,
894
+ shouldUseIncreasedScalingPercent,
895
+ ) && {
854
896
  disabled: value !== 'center',
855
897
  }),
856
898
  };
@@ -889,11 +931,26 @@ export const getSelectedAlignmentIcon = (alignmentIcons: AlignmentIcon[], select
889
931
  export const isLayoutOptionDisabled = (
890
932
  selectedNode: PMNode,
891
933
  getEditorContainerWidth: GetEditorContainerWidth,
934
+ getDomRef: (editorView: EditorView) => HTMLElement | undefined,
935
+ editorView: EditorView | null,
936
+ shouldUseIncreasedScalingPercent: boolean,
892
937
  ) => {
893
- const lineLength = getEditorContainerWidth().lineLength;
894
- const tableWidth = getTableContainerWidth(selectedNode);
938
+ const { lineLength } = getEditorContainerWidth();
939
+ let tableContainerWidth = getTableContainerWidth(selectedNode);
940
+
941
+ // table may be scaled, use the scale percent to calculate the table width
942
+ if (editorView) {
943
+ const tableWrapper = getDomRef(editorView);
944
+ const tableWrapperWidth = tableWrapper?.clientWidth || tableContainerWidth;
945
+ const scalePercent = getStaticTableScalingPercent(
946
+ selectedNode,
947
+ tableWrapperWidth,
948
+ shouldUseIncreasedScalingPercent,
949
+ );
950
+ tableContainerWidth = tableContainerWidth * scalePercent;
951
+ }
895
952
 
896
- if (selectedNode && lineLength && tableWidth > lineLength) {
953
+ if (selectedNode && lineLength && tableContainerWidth > lineLength) {
897
954
  return true;
898
955
  }
899
956
 
@@ -104,7 +104,11 @@ 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, shouldUseIncreasedScalingPercent = false) =>
107
+ (
108
+ isTableScalingEnabled = false,
109
+ isTableFixedColumnWidthsOptionEnabled = false,
110
+ shouldUseIncreasedScalingPercent = false,
111
+ ) =>
108
112
  (table: ContentNodeWithPos, view: EditorView | undefined) =>
109
113
  (tr: Transaction): Transaction => {
110
114
  if (!view) {
@@ -135,7 +139,8 @@ export const rescaleColumns =
135
139
 
136
140
  const tableDepth = view.state.doc.resolve(table.pos).depth;
137
141
  let shouldScale = isTableScalingEnabled && tableDepth === 0;
138
- if (shouldScale && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
142
+
143
+ if (shouldScale && isTableFixedColumnWidthsOptionEnabled) {
139
144
  shouldScale = newTable.attrs.displayMode !== 'fixed';
140
145
  }
141
146
 
@@ -208,7 +213,6 @@ export const rescaleColumns =
208
213
  isTableScalingEnabled: shouldScale,
209
214
  shouldUseIncreasedScalingPercent,
210
215
  });
211
-
212
216
  // Two scenarios that require scaling:
213
217
  // 1. If the new table width will result in the table going into overflow
214
218
  // we resize the cells to avoid it (e.g. adding a column)
@@ -245,6 +245,7 @@ export const deleteColumns =
245
245
  allowCustomStep: boolean,
246
246
  view?: EditorView,
247
247
  isTableScalingEnabled = false,
248
+ isTableFixedColumnWidthsOptionEnabled = false,
248
249
  shouldUseIncreasedScalingPercent = false,
249
250
  ) =>
250
251
  (tr: Transaction) => {
@@ -259,9 +260,12 @@ export const deleteColumns =
259
260
  updatedTr = deleteColumnsLegacy(rect)(updatedTr);
260
261
  }
261
262
  const table = findTable(updatedTr.selection);
262
-
263
263
  if (table) {
264
- updatedTr = rescaleColumns(isTableScalingEnabled, shouldUseIncreasedScalingPercent)(
264
+ updatedTr = rescaleColumns(
265
+ isTableScalingEnabled,
266
+ isTableFixedColumnWidthsOptionEnabled,
267
+ shouldUseIncreasedScalingPercent,
268
+ )(
265
269
  table,
266
270
  view,
267
271
  )(updatedTr);