@atlaskit/editor-plugin-table 7.5.4 → 7.5.6

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 (236) hide show
  1. package/CHANGELOG.md +13 -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 +27 -11
  7. package/dist/cjs/nodeviews/OverflowShadowsObserver.js +24 -15
  8. package/dist/cjs/nodeviews/TableCell.js +5 -30
  9. package/dist/cjs/nodeviews/TableComponent.js +120 -83
  10. package/dist/cjs/nodeviews/TableContainer.js +23 -21
  11. package/dist/cjs/nodeviews/TableResizer.js +13 -13
  12. package/dist/cjs/nodeviews/table.js +9 -9
  13. package/dist/cjs/plugin.js +60 -59
  14. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +13 -13
  15. package/dist/cjs/pm-plugins/keymap.js +6 -8
  16. package/dist/cjs/pm-plugins/main.js +7 -24
  17. package/dist/cjs/pm-plugins/sticky-headers/plugin.js +2 -3
  18. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +12 -12
  19. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  20. package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +4 -2
  21. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +2 -2
  22. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +3 -3
  23. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +3 -3
  24. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +11 -12
  25. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  26. package/dist/cjs/pm-plugins/table-width.js +6 -2
  27. package/dist/cjs/toolbar.js +21 -21
  28. package/dist/cjs/transforms/column-width.js +4 -4
  29. package/dist/cjs/transforms/delete-columns.js +2 -2
  30. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +53 -55
  31. package/dist/cjs/ui/FloatingContextualMenu/index.js +2 -4
  32. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +2 -2
  33. package/dist/cjs/ui/FloatingDragMenu/index.js +6 -6
  34. package/dist/cjs/ui/FloatingInsertButton/index.js +6 -7
  35. package/dist/cjs/ui/TableFloatingColumnControls/index.js +8 -48
  36. package/dist/cjs/ui/TableFloatingControls/index.js +113 -223
  37. package/dist/cjs/utils/column-controls.js +5 -5
  38. package/dist/cjs/utils/create.js +2 -5
  39. package/dist/cjs/utils/dom.js +13 -15
  40. package/dist/cjs/utils/drag-menu.js +4 -4
  41. package/dist/es2019/commands/column-resize.js +3 -3
  42. package/dist/es2019/commands/delete.js +2 -2
  43. package/dist/es2019/commands/insert.js +12 -12
  44. package/dist/es2019/commands-with-analytics.js +6 -6
  45. package/dist/es2019/event-handlers.js +27 -11
  46. package/dist/es2019/nodeviews/OverflowShadowsObserver.js +24 -15
  47. package/dist/es2019/nodeviews/TableCell.js +1 -24
  48. package/dist/es2019/nodeviews/TableComponent.js +88 -63
  49. package/dist/es2019/nodeviews/TableContainer.js +20 -22
  50. package/dist/es2019/nodeviews/TableResizer.js +13 -13
  51. package/dist/es2019/nodeviews/table.js +9 -9
  52. package/dist/es2019/plugin.js +19 -20
  53. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +6 -6
  54. package/dist/es2019/pm-plugins/keymap.js +5 -8
  55. package/dist/es2019/pm-plugins/main.js +6 -23
  56. package/dist/es2019/pm-plugins/sticky-headers/plugin.js +1 -1
  57. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +5 -5
  58. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  59. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +3 -1
  60. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
  61. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +2 -2
  62. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +3 -2
  63. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +12 -13
  64. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  65. package/dist/es2019/pm-plugins/table-width.js +6 -2
  66. package/dist/es2019/toolbar.js +15 -15
  67. package/dist/es2019/transforms/column-width.js +5 -5
  68. package/dist/es2019/transforms/delete-columns.js +2 -2
  69. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +9 -12
  70. package/dist/es2019/ui/FloatingContextualMenu/index.js +2 -4
  71. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +2 -2
  72. package/dist/es2019/ui/FloatingDragMenu/index.js +5 -5
  73. package/dist/es2019/ui/FloatingInsertButton/index.js +5 -6
  74. package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -27
  75. package/dist/es2019/ui/TableFloatingControls/index.js +119 -193
  76. package/dist/es2019/utils/column-controls.js +6 -6
  77. package/dist/es2019/utils/create.js +2 -5
  78. package/dist/es2019/utils/dom.js +13 -15
  79. package/dist/es2019/utils/drag-menu.js +4 -4
  80. package/dist/esm/commands/column-resize.js +3 -3
  81. package/dist/esm/commands/delete.js +2 -2
  82. package/dist/esm/commands/insert.js +15 -15
  83. package/dist/esm/commands-with-analytics.js +7 -7
  84. package/dist/esm/event-handlers.js +27 -11
  85. package/dist/esm/nodeviews/OverflowShadowsObserver.js +24 -15
  86. package/dist/esm/nodeviews/TableCell.js +5 -30
  87. package/dist/esm/nodeviews/TableComponent.js +119 -82
  88. package/dist/esm/nodeviews/TableContainer.js +24 -22
  89. package/dist/esm/nodeviews/TableResizer.js +13 -13
  90. package/dist/esm/nodeviews/table.js +9 -9
  91. package/dist/esm/plugin.js +60 -59
  92. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +13 -13
  93. package/dist/esm/pm-plugins/keymap.js +6 -8
  94. package/dist/esm/pm-plugins/main.js +7 -24
  95. package/dist/esm/pm-plugins/sticky-headers/plugin.js +2 -3
  96. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +12 -12
  97. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  98. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +3 -1
  99. package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
  100. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +2 -2
  101. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +4 -3
  102. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +13 -14
  103. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  104. package/dist/esm/pm-plugins/table-width.js +6 -2
  105. package/dist/esm/toolbar.js +21 -21
  106. package/dist/esm/transforms/column-width.js +5 -5
  107. package/dist/esm/transforms/delete-columns.js +2 -2
  108. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +53 -55
  109. package/dist/esm/ui/FloatingContextualMenu/index.js +2 -4
  110. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +2 -2
  111. package/dist/esm/ui/FloatingDragMenu/index.js +6 -6
  112. package/dist/esm/ui/FloatingInsertButton/index.js +6 -7
  113. package/dist/esm/ui/TableFloatingColumnControls/index.js +8 -48
  114. package/dist/esm/ui/TableFloatingControls/index.js +113 -224
  115. package/dist/esm/utils/column-controls.js +6 -6
  116. package/dist/esm/utils/create.js +2 -5
  117. package/dist/esm/utils/dom.js +13 -15
  118. package/dist/esm/utils/drag-menu.js +4 -4
  119. package/dist/types/commands/column-resize.d.ts +1 -1
  120. package/dist/types/commands/delete.d.ts +1 -1
  121. package/dist/types/commands/insert.d.ts +7 -7
  122. package/dist/types/commands-with-analytics.d.ts +3 -3
  123. package/dist/types/event-handlers.d.ts +4 -5
  124. package/dist/types/nodeviews/OverflowShadowsObserver.d.ts +3 -1
  125. package/dist/types/nodeviews/TableCell.d.ts +1 -5
  126. package/dist/types/nodeviews/TableComponent.d.ts +6 -3
  127. package/dist/types/nodeviews/TableContainer.d.ts +6 -4
  128. package/dist/types/nodeviews/TableResizer.d.ts +2 -2
  129. package/dist/types/nodeviews/table.d.ts +1 -1
  130. package/dist/types/nodeviews/types.d.ts +1 -0
  131. package/dist/types/plugin.d.ts +1 -0
  132. package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +1 -2
  133. package/dist/types/pm-plugins/keymap.d.ts +2 -2
  134. package/dist/types/pm-plugins/main.d.ts +1 -1
  135. package/dist/types/pm-plugins/sticky-headers/plugin.d.ts +2 -3
  136. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  137. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  138. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  139. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  140. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -1
  141. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -4
  142. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  143. package/dist/types/pm-plugins/table-width.d.ts +1 -2
  144. package/dist/types/toolbar.d.ts +2 -2
  145. package/dist/types/transforms/column-width.d.ts +1 -1
  146. package/dist/types/transforms/delete-columns.d.ts +1 -1
  147. package/dist/types/types.d.ts +1 -3
  148. package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
  149. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
  150. package/dist/types/ui/FloatingDragMenu/index.d.ts +2 -3
  151. package/dist/types/ui/FloatingInsertButton/index.d.ts +1 -2
  152. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -1
  153. package/dist/types/ui/TableFloatingControls/index.d.ts +5 -22
  154. package/dist/types/utils/create.d.ts +1 -2
  155. package/dist/types/utils/dom.d.ts +10 -2
  156. package/dist/types/utils/drag-menu.d.ts +1 -1
  157. package/dist/types-ts4.5/commands/column-resize.d.ts +1 -1
  158. package/dist/types-ts4.5/commands/delete.d.ts +1 -1
  159. package/dist/types-ts4.5/commands/insert.d.ts +7 -7
  160. package/dist/types-ts4.5/commands-with-analytics.d.ts +3 -3
  161. package/dist/types-ts4.5/event-handlers.d.ts +4 -5
  162. package/dist/types-ts4.5/nodeviews/OverflowShadowsObserver.d.ts +3 -1
  163. package/dist/types-ts4.5/nodeviews/TableCell.d.ts +1 -5
  164. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +6 -3
  165. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +6 -4
  166. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -2
  167. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -1
  168. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  169. package/dist/types-ts4.5/plugin.d.ts +1 -0
  170. package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +1 -2
  171. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -2
  172. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  173. package/dist/types-ts4.5/pm-plugins/sticky-headers/plugin.d.ts +2 -3
  174. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  175. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  176. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  177. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  178. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -1
  179. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -4
  180. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  181. package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -2
  182. package/dist/types-ts4.5/toolbar.d.ts +2 -2
  183. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
  184. package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
  185. package/dist/types-ts4.5/types.d.ts +1 -3
  186. package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
  187. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
  188. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +2 -3
  189. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +1 -2
  190. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -1
  191. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +5 -22
  192. package/dist/types-ts4.5/utils/create.d.ts +1 -2
  193. package/dist/types-ts4.5/utils/dom.d.ts +10 -2
  194. package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
  195. package/package.json +3 -4
  196. package/src/commands/column-resize.ts +4 -3
  197. package/src/commands/delete.ts +2 -2
  198. package/src/commands/insert.ts +15 -27
  199. package/src/commands-with-analytics.ts +6 -9
  200. package/src/event-handlers.ts +107 -105
  201. package/src/nodeviews/OverflowShadowsObserver.ts +32 -21
  202. package/src/nodeviews/TableCell.ts +0 -26
  203. package/src/nodeviews/TableComponent.tsx +107 -78
  204. package/src/nodeviews/TableContainer.tsx +26 -32
  205. package/src/nodeviews/TableResizer.tsx +15 -18
  206. package/src/nodeviews/table.tsx +6 -5
  207. package/src/nodeviews/types.ts +1 -0
  208. package/src/plugin.tsx +17 -32
  209. package/src/pm-plugins/drag-and-drop/plugin.ts +10 -15
  210. package/src/pm-plugins/keymap.ts +6 -13
  211. package/src/pm-plugins/main.ts +6 -25
  212. package/src/pm-plugins/sticky-headers/plugin.ts +2 -11
  213. package/src/pm-plugins/table-resizing/event-handlers.ts +6 -4
  214. package/src/pm-plugins/table-resizing/utils/colgroup.ts +2 -2
  215. package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
  216. package/src/pm-plugins/table-resizing/utils/index.ts +1 -1
  217. package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
  218. package/src/pm-plugins/table-resizing/utils/resize-column.ts +5 -2
  219. package/src/pm-plugins/table-resizing/utils/resize-state.ts +18 -13
  220. package/src/pm-plugins/table-resizing/utils/scale-table.ts +14 -14
  221. package/src/pm-plugins/table-width.ts +4 -6
  222. package/src/toolbar.tsx +16 -19
  223. package/src/transforms/column-width.ts +7 -6
  224. package/src/transforms/delete-columns.ts +2 -2
  225. package/src/types.ts +1 -4
  226. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +11 -16
  227. package/src/ui/FloatingContextualMenu/index.tsx +0 -2
  228. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -3
  229. package/src/ui/FloatingDragMenu/index.tsx +4 -8
  230. package/src/ui/FloatingInsertButton/index.tsx +11 -22
  231. package/src/ui/TableFloatingColumnControls/index.tsx +5 -29
  232. package/src/ui/TableFloatingControls/index.tsx +155 -241
  233. package/src/utils/column-controls.ts +5 -6
  234. package/src/utils/create.ts +2 -5
  235. package/src/utils/dom.ts +12 -19
  236. package/src/utils/drag-menu.ts +7 -12
@@ -22,11 +22,7 @@ import type {
22
22
  EditorContainerWidth,
23
23
  GetEditorFeatureFlags,
24
24
  } from '@atlaskit/editor-common/types';
25
- import {
26
- browser,
27
- calcTableColumnWidths,
28
- isValidPosition,
29
- } from '@atlaskit/editor-common/utils';
25
+ import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
30
26
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
31
27
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
32
28
  import {
@@ -59,6 +55,7 @@ import {
59
55
  updateColgroup,
60
56
  } from '../pm-plugins/table-resizing/utils';
61
57
  import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
58
+ import { TABLE_EDITOR_MARGIN } from '../pm-plugins/table-resizing/utils/consts';
62
59
  import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
63
60
  import type { PluginInjectionAPI } from '../types';
64
61
  import { TableCssClassName as ClassName, ShadowEvent } from '../types';
@@ -87,6 +84,12 @@ const isIE11 = browser.ie_version === 11;
87
84
  // To make sure we capture the last update, we use setTimeout.
88
85
  const initialOverflowCaptureTimeroutDelay = 300;
89
86
 
87
+ // This is a hard switch for controlling whether the overflow analytics should be dispatched. There has been 6months of data
88
+ // already collected which we could use but have not. This has been disabled rather then removed entirely in the event that
89
+ // the current collected data becomes stale and we want to start collecting fresh data again in future.
90
+ // PLEASE NOTE: that the current way this alaytics has been configured WILL cause reflows to occur. This is why the has been disabled.
91
+ const isOverflowAnalyticsEnabled = false;
92
+
90
93
  export interface ComponentProps {
91
94
  view: EditorView;
92
95
  getNode: () => PmNode;
@@ -102,13 +105,13 @@ export interface ComponentProps {
102
105
  isHeaderColumnEnabled: boolean;
103
106
  isMediaFullscreen?: boolean;
104
107
  isDragAndDropEnabled?: boolean;
108
+ isTableScalingEnabled?: boolean;
105
109
  tableActive: boolean;
106
110
  ordering: TableColumnOrdering;
107
111
  isResizing?: boolean;
108
112
  getEditorFeatureFlags: GetEditorFeatureFlags;
109
113
  dispatchAnalyticsEvent: DispatchAnalyticsEvent;
110
114
  pluginInjectionApi?: PluginInjectionAPI;
111
- tableRef?: HTMLElement | undefined;
112
115
  }
113
116
 
114
117
  interface TableState {
@@ -117,6 +120,8 @@ interface TableState {
117
120
  stickyHeader?: RowStickyState;
118
121
  [ShadowEvent.SHOW_BEFORE_SHADOW]: boolean;
119
122
  [ShadowEvent.SHOW_AFTER_SHADOW]: boolean;
123
+ tableWrapperWidth?: number;
124
+ tableWrapperHeight?: number;
120
125
  }
121
126
 
122
127
  class TableComponent extends React.Component<ComponentProps, TableState> {
@@ -127,6 +132,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
127
132
  parentWidth: undefined,
128
133
  [ShadowEvent.SHOW_BEFORE_SHADOW]: false,
129
134
  [ShadowEvent.SHOW_AFTER_SHADOW]: false,
135
+ tableWrapperWidth: undefined,
136
+ tableWrapperHeight: undefined,
130
137
  };
131
138
 
132
139
  private wrapper?: HTMLDivElement | null;
@@ -139,11 +146,10 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
139
146
 
140
147
  private isInitialOverflowSent: boolean;
141
148
  private initialOverflowCaptureTimerId?: ReturnType<typeof setTimeout>;
149
+ private resizeObserver?: ResizeObserver;
142
150
 
143
151
  private dragAndDropCleanupFn?: CleanupFn;
144
152
 
145
- private tableColumnWidths?: number[];
146
-
147
153
  constructor(props: ComponentProps) {
148
154
  super(props);
149
155
  const { options, containerWidth, getNode } = props;
@@ -163,6 +169,21 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
163
169
  },
164
170
  );
165
171
 
172
+ this.resizeObserver = new ResizeObserver((entries) => {
173
+ for (let entry of entries) {
174
+ this.setState((prev) => {
175
+ return prev?.tableWrapperWidth === entry.contentRect?.width &&
176
+ prev?.tableWrapperHeight === entry.contentRect?.height
177
+ ? prev
178
+ : {
179
+ ...prev,
180
+ tableWrapperWidth: entry.contentRect.width,
181
+ tableWrapperHeight: entry.contentRect.height,
182
+ };
183
+ });
184
+ }
185
+ });
186
+
166
187
  // Disable inline table editing and resizing controls in Firefox
167
188
  // https://github.com/ProseMirror/prosemirror/issues/432
168
189
  if ('execCommand' in document) {
@@ -182,8 +203,13 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
182
203
  isDragAndDropEnabled,
183
204
  getNode,
184
205
  getEditorFeatureFlags,
206
+ isTableScalingEnabled,
185
207
  } = this.props;
186
208
 
209
+ if (isTableScalingEnabled) {
210
+ this.handleColgroupUpdates(true);
211
+ }
212
+
187
213
  if (allowColumnResizing && this.wrapper && !isIE11) {
188
214
  this.wrapper.addEventListener('scroll', this.handleScrollDebounced, {
189
215
  passive: true,
@@ -231,11 +257,13 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
231
257
 
232
258
  eventDispatcher.on((stickyHeadersPluginKey as any).key, this.onStickyState);
233
259
 
234
- const initialIsOveflowing =
235
- this.state[ShadowEvent.SHOW_BEFORE_SHADOW] ||
236
- this.state[ShadowEvent.SHOW_AFTER_SHADOW];
260
+ if (isOverflowAnalyticsEnabled) {
261
+ const initialIsOveflowing =
262
+ this.state[ShadowEvent.SHOW_BEFORE_SHADOW] ||
263
+ this.state[ShadowEvent.SHOW_AFTER_SHADOW];
237
264
 
238
- this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
265
+ this.setTimerToSendInitialOverflowCaptured(initialIsOveflowing);
266
+ }
239
267
  }
240
268
 
241
269
  componentWillUnmount() {
@@ -254,6 +282,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
254
282
  this.dragAndDropCleanupFn();
255
283
  }
256
284
 
285
+ this.resizeObserver?.disconnect();
286
+
257
287
  const { stickyScrollbar } = getEditorFeatureFlags();
258
288
 
259
289
  if (stickyScrollbar) {
@@ -288,20 +318,17 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
288
318
  }
289
319
  }
290
320
 
291
- handleColgroupUpdates() {
292
- const { getNode, containerWidth, isResizing, view, getPos, tableRef } =
293
- this.props;
321
+ handleColgroupUpdates(force = false) {
322
+ const { getNode, containerWidth, isResizing, view, getPos } = this.props;
294
323
 
295
- if (!tableRef) {
324
+ if (!this.table) {
296
325
  return;
297
326
  }
298
327
 
299
- const TABLE_MARGIN = 76;
300
-
301
328
  // Remove any widths styles after resizing preview is completed
302
- tableRef.style.width = '';
329
+ this.table.style.width = '';
303
330
 
304
- const tableRenderWidth = containerWidth.width - TABLE_MARGIN;
331
+ const tableRenderWidth = containerWidth.width - TABLE_EDITOR_MARGIN;
305
332
  const tableNode = getNode();
306
333
  const start = getPos() || 0;
307
334
  const depth = view.state.doc.resolve(start).depth;
@@ -312,39 +339,25 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
312
339
  }
313
340
 
314
341
  const { width: tableNodeWidth } = tableNode.attrs;
315
- const tableColumnWidths = calcTableColumnWidths(tableNode);
316
342
  const shouldTableScale = tableRenderWidth < tableNodeWidth;
317
- let isTableColumnWidthsSame = false;
318
- if (this.tableColumnWidths) {
319
- isTableColumnWidthsSame = tableColumnWidths?.every(
320
- (width, index) => width === this.tableColumnWidths![index],
321
- );
322
- }
343
+
323
344
  const { width: containerWidthValue } = containerWidth;
324
345
  const isWidthChanged = this.containerWidth?.width !== containerWidthValue;
325
346
 
326
- if (
327
- shouldTableScale &&
328
- !isResizing &&
329
- (!isTableColumnWidthsSame || isWidthChanged)
330
- ) {
347
+ if (force || (shouldTableScale && !isResizing && isWidthChanged)) {
331
348
  const resizeState = getResizeState({
332
349
  minWidth: COLUMN_MIN_WIDTH,
333
350
  maxSize: tableRenderWidth,
334
351
  table: tableNode,
335
- tableRef: this.table as HTMLTableElement,
352
+ tableRef: this.table,
336
353
  start,
337
354
  domAtPos: view.domAtPos,
338
- tablePreserveWidth: true,
355
+ isTableScalingEnabled: true,
339
356
  });
340
357
 
341
- requestAnimationFrame(() => {
342
- updateColgroup(resizeState, this.table!, true);
343
- });
344
-
345
- this.tableColumnWidths = tableColumnWidths;
346
- this.containerWidth = containerWidth;
358
+ updateColgroup(resizeState, this.table!, tableNode, true);
347
359
  }
360
+ this.containerWidth = containerWidth;
348
361
  }
349
362
 
350
363
  componentDidUpdate(_: any, prevState: TableState) {
@@ -355,13 +368,12 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
355
368
  allowColumnResizing,
356
369
  isResizing,
357
370
  options,
358
- getEditorFeatureFlags,
371
+ isTableScalingEnabled,
359
372
  } = this.props;
360
373
  const { isInDanger } = getPluginState(view.state);
361
- const { tablePreserveWidth = false } = getEditorFeatureFlags();
362
374
  const table = findTable(view.state.selection);
363
375
 
364
- if (tablePreserveWidth) {
376
+ if (isTableScalingEnabled) {
365
377
  this.handleColgroupUpdates();
366
378
  }
367
379
 
@@ -424,7 +436,11 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
424
436
  isResizing);
425
437
 
426
438
  if (shouldRecreateResizeCols) {
427
- insertColgroupFromNode(this.table, currentTable, tablePreserveWidth);
439
+ insertColgroupFromNode(
440
+ this.table,
441
+ currentTable,
442
+ isTableScalingEnabled,
443
+ );
428
444
  }
429
445
 
430
446
  updateControls()(view.state);
@@ -432,38 +448,42 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
432
448
 
433
449
  this.handleTableResizingDebounced();
434
450
  }
451
+ if (isOverflowAnalyticsEnabled) {
452
+ const newIsOverflowing =
453
+ this.state[ShadowEvent.SHOW_BEFORE_SHADOW] ||
454
+ this.state[ShadowEvent.SHOW_AFTER_SHADOW];
435
455
 
436
- const newIsOverflowing =
437
- this.state[ShadowEvent.SHOW_BEFORE_SHADOW] ||
438
- this.state[ShadowEvent.SHOW_AFTER_SHADOW];
456
+ const prevIsOverflowing =
457
+ prevState[ShadowEvent.SHOW_BEFORE_SHADOW] ||
458
+ prevState[ShadowEvent.SHOW_AFTER_SHADOW];
439
459
 
440
- const prevIsOverflowing =
441
- prevState[ShadowEvent.SHOW_BEFORE_SHADOW] ||
442
- prevState[ShadowEvent.SHOW_AFTER_SHADOW];
443
-
444
- if (this.initialOverflowCaptureTimerId) {
445
- clearTimeout(this.initialOverflowCaptureTimerId);
446
- }
447
-
448
- if (!this.isInitialOverflowSent) {
449
- this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
450
- }
460
+ if (this.initialOverflowCaptureTimerId) {
461
+ clearTimeout(this.initialOverflowCaptureTimerId);
462
+ }
451
463
 
452
- if (this.isInitialOverflowSent && prevIsOverflowing !== newIsOverflowing) {
453
- const {
454
- dispatch,
455
- state: { tr },
456
- } = this.props.view;
464
+ if (!this.isInitialOverflowSent) {
465
+ this.setTimerToSendInitialOverflowCaptured(newIsOverflowing);
466
+ }
457
467
 
458
- dispatch(
459
- tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
460
- isOverflowing: newIsOverflowing,
461
- wasOverflowing: prevIsOverflowing,
462
- editorWidth: this.props.containerWidth.width || 0,
463
- width: this.node.attrs.width || 0,
464
- parentWidth: this.state?.parentWidth || 0,
465
- }),
466
- );
468
+ if (
469
+ this.isInitialOverflowSent &&
470
+ prevIsOverflowing !== newIsOverflowing
471
+ ) {
472
+ const {
473
+ dispatch,
474
+ state: { tr },
475
+ } = this.props.view;
476
+
477
+ dispatch(
478
+ tr.setMeta(META_KEYS.OVERFLOW_STATE_CHANGED, {
479
+ isOverflowing: newIsOverflowing,
480
+ wasOverflowing: prevIsOverflowing,
481
+ editorWidth: this.props.containerWidth.width || 0,
482
+ width: this.node.attrs.width || 0,
483
+ parentWidth: this.state?.parentWidth || 0,
484
+ }),
485
+ );
486
+ }
467
487
  }
468
488
  }
469
489
 
@@ -485,6 +505,12 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
485
505
  }
486
506
  };
487
507
 
508
+ private observeTable(table: HTMLTableElement | null) {
509
+ if (table) {
510
+ this.resizeObserver?.observe(table);
511
+ }
512
+ }
513
+
488
514
  onStickyState = (state: StickyPluginState) => {
489
515
  const pos = this.props.getPos();
490
516
  if (!isValidPosition(pos, this.props.view.state)) {
@@ -517,6 +543,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
517
543
  pluginInjectionApi,
518
544
  isDragAndDropEnabled,
519
545
  getEditorFeatureFlags,
546
+ isTableScalingEnabled,
520
547
  } = this.props;
521
548
 
522
549
  const { showBeforeShadow, showAfterShadow } = this.state;
@@ -552,6 +579,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
552
579
  selection={view.state.selection}
553
580
  headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
554
581
  stickyHeader={this.state.stickyHeader}
582
+ tableWrapperWidth={this.state.tableWrapperWidth}
555
583
  />
556
584
  );
557
585
  const tableContainerWidth = getTableContainerWidth(node);
@@ -576,6 +604,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
576
604
  tableContainerWidth={tableContainerWidth}
577
605
  isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
578
606
  getScrollOffset={() => this.wrapper?.scrollLeft || 0}
607
+ tableWrapperHeight={this.state.tableWrapperHeight}
579
608
  />
580
609
  ) : null;
581
610
 
@@ -610,7 +639,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
610
639
  shadowPadding +
611
640
  2;
612
641
 
613
- const { stickyScrollbar, tablePreserveWidth } = getEditorFeatureFlags();
642
+ const { stickyScrollbar } = getEditorFeatureFlags();
614
643
 
615
644
  return (
616
645
  <TableContainer
@@ -628,9 +657,10 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
628
657
  isBreakoutEnabled={options?.isBreakoutEnabled}
629
658
  isNested={isNested}
630
659
  pluginInjectionApi={pluginInjectionApi}
660
+ tableWrapperHeight={this.state.tableWrapperHeight}
631
661
  isTableResizingEnabled={options?.isTableResizingEnabled}
632
662
  isResizing={isResizing}
633
- tablePreserveWidth={tablePreserveWidth}
663
+ isTableScalingEnabled={isTableScalingEnabled}
634
664
  >
635
665
  <div
636
666
  className={ClassName.TABLE_STICKY_SENTINEL_TOP}
@@ -681,6 +711,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
681
711
  if (tableElement !== this.table) {
682
712
  this.table = tableElement;
683
713
  this.createShadowSentinels(this.table);
714
+ this.observeTable(this.table);
684
715
  }
685
716
  }
686
717
  }}
@@ -860,7 +891,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
860
891
  getPos,
861
892
  containerWidth,
862
893
  options,
863
- getEditorFeatureFlags,
894
+ isTableScalingEnabled,
864
895
  } = this.props;
865
896
  const node = getNode();
866
897
  const { state, dispatch } = view;
@@ -874,8 +905,6 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
874
905
 
875
906
  this.scaleTableDebounced.cancel();
876
907
 
877
- const { tablePreserveWidth = false } = getEditorFeatureFlags();
878
-
879
908
  const tr = scaleTable(
880
909
  this.table,
881
910
  {
@@ -888,7 +917,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
888
917
  ...options,
889
918
  },
890
919
  domAtPos,
891
- tablePreserveWidth,
920
+ isTableScalingEnabled,
892
921
  )(state.tr);
893
922
 
894
923
  dispatch(tr);
@@ -1,5 +1,5 @@
1
1
  import type { PropsWithChildren } from 'react';
2
- import React, { forwardRef, useCallback, useRef } from 'react';
2
+ import React, { forwardRef, useCallback, useRef, useState } from 'react';
3
3
 
4
4
  import classNames from 'classnames';
5
5
 
@@ -77,7 +77,8 @@ type ResizableTableContainerProps = {
77
77
  tableRef: HTMLTableElement;
78
78
  isResizing?: boolean;
79
79
  pluginInjectionApi?: PluginInjectionAPI;
80
- tablePreserveWidth?: boolean;
80
+ isTableScalingEnabled?: boolean;
81
+ tableWrapperHeight?: number;
81
82
  };
82
83
 
83
84
  export const ResizableTableContainer = React.memo(
@@ -91,10 +92,12 @@ export const ResizableTableContainer = React.memo(
91
92
  tableRef,
92
93
  isResizing,
93
94
  pluginInjectionApi,
94
- tablePreserveWidth,
95
+ isTableScalingEnabled,
96
+ tableWrapperHeight,
95
97
  }: PropsWithChildren<ResizableTableContainerProps>) => {
96
98
  const containerRef = useRef<HTMLDivElement | null>(null);
97
99
  const tableWidthRef = useRef<number>(akEditorDefaultLayoutWidth);
100
+ const [resizing, setIsResizing] = useState(false);
98
101
 
99
102
  const updateContainerHeight = useCallback((height: number | 'auto') => {
100
103
  // current StickyHeader State is not stable to be fetch.
@@ -108,41 +111,26 @@ export const ResizableTableContainer = React.memo(
108
111
  // 1px is border width but collapse make it 0.5.
109
112
  // -- When sticky header appear, we should add first row height but reduce
110
113
  // collapsed border
111
- containerRef.current?.style.setProperty(
112
- 'height',
113
- typeof height === 'number' ? `${height + 40.5}px` : 'auto',
114
- );
114
+ return typeof height === 'number' ? `${height + 40.5}px` : 'auto';
115
115
  } else {
116
116
  const stickyHeaderHeight =
117
117
  containerRef.current
118
118
  ?.getElementsByTagName('th')[0]
119
119
  .getBoundingClientRect().height || 0;
120
- containerRef.current?.style.setProperty(
121
- 'height',
122
- typeof height === 'number'
123
- ? `${height + stickyHeaderHeight + 39.5}px`
124
- : 'auto',
125
- );
120
+
121
+ return typeof height === 'number'
122
+ ? `${height + stickyHeaderHeight + 39.5}px`
123
+ : 'auto';
126
124
  }
127
125
  }, []);
128
126
 
129
- const resizeObserverRef = useRef(
130
- new ResizeObserver((entries) => {
131
- updateContainerHeight(entries[entries.length - 1].contentRect.height);
132
- }),
133
- );
134
-
135
127
  const onResizeStart = useCallback(() => {
136
- if (tableRef) {
137
- resizeObserverRef.current.observe(tableRef);
138
- }
139
- }, [tableRef]);
128
+ setIsResizing(true);
129
+ }, []);
140
130
 
141
131
  const onResizeStop = useCallback(() => {
142
- updateContainerHeight('auto');
143
-
144
- resizeObserverRef.current.disconnect();
145
- }, [updateContainerHeight]);
132
+ setIsResizing(false);
133
+ }, []);
146
134
 
147
135
  const updateWidth = useCallback((width: number) => {
148
136
  if (!containerRef.current) {
@@ -191,7 +179,7 @@ export const ResizableTableContainer = React.memo(
191
179
 
192
180
  const tableWidth = getTableContainerWidth(node);
193
181
  // 76 is currently an accepted padding value considering the spacing for resizer handle
194
- const responsiveContainerWidth = tablePreserveWidth
182
+ const responsiveContainerWidth = isTableScalingEnabled
195
183
  ? containerWidth -
196
184
  akEditorGutterPadding * 2 -
197
185
  akEditorMediaResizeHandlerPaddingWide / 2
@@ -218,7 +206,7 @@ export const ResizableTableContainer = React.memo(
218
206
  displayGuideline,
219
207
  attachAnalyticsEvent,
220
208
  displayGapCursor,
221
- tablePreserveWidth,
209
+ isTableScalingEnabled,
222
210
  };
223
211
 
224
212
  if (getBooleanFF('platform.editor.resizing-table-height-improvement')) {
@@ -239,6 +227,9 @@ export const ResizableTableContainer = React.memo(
239
227
  <div
240
228
  style={{
241
229
  width: tableWidthRef.current,
230
+ height: resizing
231
+ ? updateContainerHeight(tableWrapperHeight ?? 'auto')
232
+ : 'auto',
242
233
  }}
243
234
  className={ClassName.TABLE_RESIZER_CONTAINER}
244
235
  ref={containerRef}
@@ -266,7 +257,8 @@ type TableContainerProps = {
266
257
  isNested: boolean;
267
258
  isResizing?: boolean;
268
259
  pluginInjectionApi?: PluginInjectionAPI;
269
- tablePreserveWidth?: boolean;
260
+ isTableScalingEnabled?: boolean;
261
+ tableWrapperHeight?: number;
270
262
  };
271
263
 
272
264
  export const TableContainer = ({
@@ -280,9 +272,10 @@ export const TableContainer = ({
280
272
  getPos,
281
273
  tableRef,
282
274
  isNested,
275
+ tableWrapperHeight,
283
276
  isResizing,
284
277
  pluginInjectionApi,
285
- tablePreserveWidth,
278
+ isTableScalingEnabled,
286
279
  }: PropsWithChildren<TableContainerProps>) => {
287
280
  if (isTableResizingEnabled && !isNested) {
288
281
  return (
@@ -293,9 +286,10 @@ export const TableContainer = ({
293
286
  editorView={editorView}
294
287
  getPos={getPos}
295
288
  tableRef={tableRef}
289
+ tableWrapperHeight={tableWrapperHeight}
296
290
  isResizing={isResizing}
297
291
  pluginInjectionApi={pluginInjectionApi}
298
- tablePreserveWidth={tablePreserveWidth}
292
+ isTableScalingEnabled={isTableScalingEnabled}
299
293
  >
300
294
  {children}
301
295
  </ResizableTableContainer>
@@ -75,7 +75,7 @@ interface TableResizerProps {
75
75
  payload: TableEventPayload,
76
76
  ) => ((tr: Transaction) => boolean) | undefined;
77
77
  displayGapCursor: (toggle: boolean) => boolean;
78
- tablePreserveWidth?: boolean;
78
+ isTableScalingEnabled?: boolean;
79
79
  }
80
80
 
81
81
  export interface TableResizerImprovementProps extends TableResizerProps {
@@ -125,10 +125,7 @@ const getResizerHandleHeight = (
125
125
 
126
126
  const getResizerMinWidth = (node: PMNode) => {
127
127
  const currentColumnCount = getColgroupChildrenLength(node);
128
- const minColumnWidth =
129
- currentColumnCount <= 3
130
- ? currentColumnCount * COLUMN_MIN_WIDTH
131
- : 3 * COLUMN_MIN_WIDTH;
128
+ const minColumnWidth = Math.min(3, currentColumnCount) * COLUMN_MIN_WIDTH;
132
129
  // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
133
130
  // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
134
131
  return minColumnWidth + 1;
@@ -170,7 +167,7 @@ export const TableResizer = ({
170
167
  displayGuideline,
171
168
  attachAnalyticsEvent,
172
169
  displayGapCursor,
173
- tablePreserveWidth,
170
+ isTableScalingEnabled,
174
171
  }: PropsWithChildren<TableResizerImprovementProps>) => {
175
172
  const currentGap = useRef(0);
176
173
  // track resizing state - use ref over state to avoid re-render
@@ -218,7 +215,7 @@ export const TableResizer = ({
218
215
  if (gap !== currentGap.current) {
219
216
  currentGap.current = gap;
220
217
  const visibleGuidelines = getVisibleGuidelines(
221
- tablePreserveWidth
218
+ isTableScalingEnabled
222
219
  ? defaultGuidelinesForPreserveTable(containerWidth)
223
220
  : defaultGuidelines,
224
221
  containerWidth,
@@ -234,19 +231,19 @@ export const TableResizer = ({
234
231
  );
235
232
  }
236
233
  },
237
- [tablePreserveWidth, containerWidth, displayGuideline],
234
+ [isTableScalingEnabled, containerWidth, displayGuideline],
238
235
  );
239
236
 
240
237
  const guidelineSnaps = useMemo(
241
238
  () =>
242
239
  snappingEnabled
243
240
  ? {
244
- x: tablePreserveWidth
241
+ x: isTableScalingEnabled
245
242
  ? defaultTablePreserveSnappingWidths(containerWidth)
246
243
  : defaultSnappingWidths,
247
244
  }
248
245
  : undefined,
249
- [snappingEnabled, tablePreserveWidth, containerWidth],
246
+ [snappingEnabled, isTableScalingEnabled, containerWidth],
250
247
  );
251
248
 
252
249
  useEffect(() => {
@@ -282,7 +279,7 @@ export const TableResizer = ({
282
279
  dispatch(tr);
283
280
 
284
281
  const visibleGuidelines = getVisibleGuidelines(
285
- tablePreserveWidth
282
+ isTableScalingEnabled
286
283
  ? defaultGuidelinesForPreserveTable(containerWidth)
287
284
  : defaultGuidelines,
288
285
  containerWidth,
@@ -299,7 +296,7 @@ export const TableResizer = ({
299
296
  startMeasure,
300
297
  editorView,
301
298
  displayGapCursor,
302
- tablePreserveWidth,
299
+ isTableScalingEnabled,
303
300
  containerWidth,
304
301
  displayGuideline,
305
302
  onResizeStart,
@@ -328,16 +325,16 @@ export const TableResizer = ({
328
325
  parentWidth: newWidth,
329
326
  },
330
327
  editorView.domAtPos.bind(editorView),
331
- tablePreserveWidth,
328
+ isTableScalingEnabled,
332
329
  );
333
330
 
334
331
  updateActiveGuidelines(
335
332
  findClosestSnap(
336
333
  newWidth,
337
- tablePreserveWidth
334
+ isTableScalingEnabled
338
335
  ? defaultTablePreserveSnappingWidths(containerWidth)
339
336
  : defaultSnappingWidths,
340
- tablePreserveWidth
337
+ isTableScalingEnabled
341
338
  ? defaultGuidelinesForPreserveTable(containerWidth)
342
339
  : defaultGuidelines,
343
340
  TABLE_HIGHLIGHT_GAP,
@@ -350,7 +347,7 @@ export const TableResizer = ({
350
347
  },
351
348
  [
352
349
  countFrames,
353
- tablePreserveWidth,
350
+ isTableScalingEnabled,
354
351
  tableRef,
355
352
  node,
356
353
  editorView,
@@ -400,7 +397,7 @@ export const TableResizer = ({
400
397
  parentWidth: newWidth,
401
398
  },
402
399
  editorView.domAtPos.bind(editorView),
403
- tablePreserveWidth,
400
+ isTableScalingEnabled,
404
401
  )(tr);
405
402
 
406
403
  const scaledNode = tr.doc.nodeAt(pos)!;
@@ -441,7 +438,7 @@ export const TableResizer = ({
441
438
  attachAnalyticsEvent,
442
439
  endMeasure,
443
440
  onResizeStop,
444
- tablePreserveWidth,
441
+ isTableScalingEnabled,
445
442
  ],
446
443
  );
447
444