@atlaskit/editor-plugin-table 7.5.3 → 7.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/commands/column-resize.js +3 -3
  3. package/dist/cjs/commands/delete.js +2 -2
  4. package/dist/cjs/commands/insert.js +15 -15
  5. package/dist/cjs/commands-with-analytics.js +7 -7
  6. package/dist/cjs/event-handlers.js +2 -2
  7. package/dist/cjs/nodeviews/TableComponent.js +46 -59
  8. package/dist/cjs/nodeviews/TableContainer.js +5 -5
  9. package/dist/cjs/nodeviews/TableResizer.js +12 -12
  10. package/dist/cjs/nodeviews/table.js +9 -9
  11. package/dist/cjs/plugin.js +58 -56
  12. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +13 -13
  13. package/dist/cjs/pm-plugins/keymap.js +6 -8
  14. package/dist/cjs/pm-plugins/main.js +4 -6
  15. package/dist/cjs/pm-plugins/sticky-headers/plugin.js +2 -3
  16. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +12 -12
  17. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  18. package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +4 -2
  19. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +2 -2
  20. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +3 -3
  21. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +3 -3
  22. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +11 -12
  23. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  24. package/dist/cjs/pm-plugins/table-width.js +6 -2
  25. package/dist/cjs/toolbar.js +21 -21
  26. package/dist/cjs/transforms/column-width.js +4 -4
  27. package/dist/cjs/transforms/delete-columns.js +2 -2
  28. package/dist/cjs/ui/ColumnResizeWidget/index.js +4 -5
  29. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +53 -55
  30. package/dist/cjs/ui/FloatingContextualMenu/index.js +2 -4
  31. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +2 -2
  32. package/dist/cjs/ui/FloatingDragMenu/index.js +6 -6
  33. package/dist/cjs/ui/FloatingInsertButton/index.js +6 -7
  34. package/dist/cjs/utils/create.js +2 -5
  35. package/dist/cjs/utils/drag-menu.js +4 -4
  36. package/dist/cjs/utils/guidelines.js +5 -2
  37. package/dist/cjs/utils/snapping.js +14 -1
  38. package/dist/es2019/commands/column-resize.js +3 -3
  39. package/dist/es2019/commands/delete.js +2 -2
  40. package/dist/es2019/commands/insert.js +12 -12
  41. package/dist/es2019/commands-with-analytics.js +6 -6
  42. package/dist/es2019/event-handlers.js +2 -2
  43. package/dist/es2019/nodeviews/TableComponent.js +25 -36
  44. package/dist/es2019/nodeviews/TableContainer.js +6 -6
  45. package/dist/es2019/nodeviews/TableResizer.js +14 -14
  46. package/dist/es2019/nodeviews/table.js +9 -9
  47. package/dist/es2019/plugin.js +17 -17
  48. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +6 -6
  49. package/dist/es2019/pm-plugins/keymap.js +5 -8
  50. package/dist/es2019/pm-plugins/main.js +3 -5
  51. package/dist/es2019/pm-plugins/sticky-headers/plugin.js +1 -1
  52. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +5 -5
  53. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  54. package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +3 -1
  55. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
  56. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +2 -2
  57. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +3 -2
  58. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +12 -13
  59. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  60. package/dist/es2019/pm-plugins/table-width.js +6 -2
  61. package/dist/es2019/toolbar.js +15 -15
  62. package/dist/es2019/transforms/column-width.js +5 -5
  63. package/dist/es2019/transforms/delete-columns.js +2 -2
  64. package/dist/es2019/ui/ColumnResizeWidget/index.js +0 -1
  65. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +9 -12
  66. package/dist/es2019/ui/FloatingContextualMenu/index.js +2 -4
  67. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +2 -2
  68. package/dist/es2019/ui/FloatingDragMenu/index.js +5 -5
  69. package/dist/es2019/ui/FloatingInsertButton/index.js +5 -6
  70. package/dist/es2019/utils/create.js +2 -5
  71. package/dist/es2019/utils/drag-menu.js +4 -4
  72. package/dist/es2019/utils/guidelines.js +3 -2
  73. package/dist/es2019/utils/snapping.js +12 -1
  74. package/dist/esm/commands/column-resize.js +3 -3
  75. package/dist/esm/commands/delete.js +2 -2
  76. package/dist/esm/commands/insert.js +15 -15
  77. package/dist/esm/commands-with-analytics.js +7 -7
  78. package/dist/esm/event-handlers.js +2 -2
  79. package/dist/esm/nodeviews/TableComponent.js +45 -58
  80. package/dist/esm/nodeviews/TableContainer.js +6 -6
  81. package/dist/esm/nodeviews/TableResizer.js +14 -14
  82. package/dist/esm/nodeviews/table.js +9 -9
  83. package/dist/esm/plugin.js +58 -56
  84. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +13 -13
  85. package/dist/esm/pm-plugins/keymap.js +6 -8
  86. package/dist/esm/pm-plugins/main.js +4 -6
  87. package/dist/esm/pm-plugins/sticky-headers/plugin.js +2 -3
  88. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +12 -12
  89. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +2 -2
  90. package/dist/esm/pm-plugins/table-resizing/utils/consts.js +3 -1
  91. package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
  92. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +2 -2
  93. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +4 -3
  94. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +13 -14
  95. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +13 -13
  96. package/dist/esm/pm-plugins/table-width.js +6 -2
  97. package/dist/esm/toolbar.js +21 -21
  98. package/dist/esm/transforms/column-width.js +5 -5
  99. package/dist/esm/transforms/delete-columns.js +2 -2
  100. package/dist/esm/ui/ColumnResizeWidget/index.js +0 -1
  101. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +53 -55
  102. package/dist/esm/ui/FloatingContextualMenu/index.js +2 -4
  103. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +2 -2
  104. package/dist/esm/ui/FloatingDragMenu/index.js +6 -6
  105. package/dist/esm/ui/FloatingInsertButton/index.js +6 -7
  106. package/dist/esm/utils/create.js +2 -5
  107. package/dist/esm/utils/drag-menu.js +4 -4
  108. package/dist/esm/utils/guidelines.js +5 -2
  109. package/dist/esm/utils/snapping.js +14 -1
  110. package/dist/types/commands/column-resize.d.ts +1 -1
  111. package/dist/types/commands/delete.d.ts +1 -1
  112. package/dist/types/commands/insert.d.ts +7 -7
  113. package/dist/types/commands-with-analytics.d.ts +3 -3
  114. package/dist/types/event-handlers.d.ts +1 -1
  115. package/dist/types/nodeviews/TableComponent.d.ts +2 -3
  116. package/dist/types/nodeviews/TableContainer.d.ts +4 -4
  117. package/dist/types/nodeviews/TableResizer.d.ts +2 -2
  118. package/dist/types/nodeviews/table.d.ts +1 -1
  119. package/dist/types/nodeviews/types.d.ts +1 -0
  120. package/dist/types/plugin.d.ts +1 -0
  121. package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +1 -2
  122. package/dist/types/pm-plugins/keymap.d.ts +2 -2
  123. package/dist/types/pm-plugins/main.d.ts +1 -1
  124. package/dist/types/pm-plugins/sticky-headers/plugin.d.ts +2 -3
  125. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  126. package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  127. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  128. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  129. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -1
  130. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -4
  131. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  132. package/dist/types/pm-plugins/table-width.d.ts +1 -2
  133. package/dist/types/toolbar.d.ts +2 -2
  134. package/dist/types/transforms/column-width.d.ts +1 -1
  135. package/dist/types/transforms/delete-columns.d.ts +1 -1
  136. package/dist/types/types.d.ts +1 -0
  137. package/dist/types/ui/ColumnResizeWidget/index.d.ts +2 -2
  138. package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
  139. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
  140. package/dist/types/ui/FloatingDragMenu/index.d.ts +2 -3
  141. package/dist/types/ui/FloatingInsertButton/index.d.ts +1 -2
  142. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +2 -2
  143. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -2
  144. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -2
  145. package/dist/types/utils/create.d.ts +1 -2
  146. package/dist/types/utils/drag-menu.d.ts +2 -2
  147. package/dist/types/utils/guidelines.d.ts +1 -0
  148. package/dist/types/utils/snapping.d.ts +2 -0
  149. package/dist/types-ts4.5/commands/column-resize.d.ts +1 -1
  150. package/dist/types-ts4.5/commands/delete.d.ts +1 -1
  151. package/dist/types-ts4.5/commands/insert.d.ts +7 -7
  152. package/dist/types-ts4.5/commands-with-analytics.d.ts +3 -3
  153. package/dist/types-ts4.5/event-handlers.d.ts +1 -1
  154. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +2 -3
  155. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -4
  156. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -2
  157. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -1
  158. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  159. package/dist/types-ts4.5/plugin.d.ts +1 -0
  160. package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +1 -2
  161. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -2
  162. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  163. package/dist/types-ts4.5/pm-plugins/sticky-headers/plugin.d.ts +2 -3
  164. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  165. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
  166. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  167. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  168. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -1
  169. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -4
  170. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
  171. package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -2
  172. package/dist/types-ts4.5/toolbar.d.ts +2 -2
  173. package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
  174. package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
  175. package/dist/types-ts4.5/types.d.ts +1 -0
  176. package/dist/types-ts4.5/ui/ColumnResizeWidget/index.d.ts +2 -2
  177. package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
  178. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
  179. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +2 -3
  180. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +1 -2
  181. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +2 -2
  182. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -2
  183. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -2
  184. package/dist/types-ts4.5/utils/create.d.ts +1 -2
  185. package/dist/types-ts4.5/utils/drag-menu.d.ts +2 -2
  186. package/dist/types-ts4.5/utils/guidelines.d.ts +1 -0
  187. package/dist/types-ts4.5/utils/snapping.d.ts +2 -0
  188. package/package.json +2 -2
  189. package/src/commands/column-resize.ts +4 -3
  190. package/src/commands/delete.ts +2 -2
  191. package/src/commands/insert.ts +15 -27
  192. package/src/commands-with-analytics.ts +6 -9
  193. package/src/event-handlers.ts +2 -2
  194. package/src/nodeviews/TableComponent.tsx +31 -46
  195. package/src/nodeviews/TableContainer.tsx +16 -7
  196. package/src/nodeviews/TableResizer.tsx +44 -24
  197. package/src/nodeviews/table.tsx +6 -5
  198. package/src/nodeviews/types.ts +1 -0
  199. package/src/plugin.tsx +12 -28
  200. package/src/pm-plugins/drag-and-drop/plugin.ts +10 -15
  201. package/src/pm-plugins/keymap.ts +6 -13
  202. package/src/pm-plugins/main.ts +3 -3
  203. package/src/pm-plugins/sticky-headers/plugin.ts +2 -11
  204. package/src/pm-plugins/table-resizing/event-handlers.ts +6 -4
  205. package/src/pm-plugins/table-resizing/utils/colgroup.ts +2 -2
  206. package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
  207. package/src/pm-plugins/table-resizing/utils/index.ts +1 -1
  208. package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
  209. package/src/pm-plugins/table-resizing/utils/resize-column.ts +5 -2
  210. package/src/pm-plugins/table-resizing/utils/resize-state.ts +18 -13
  211. package/src/pm-plugins/table-resizing/utils/scale-table.ts +14 -14
  212. package/src/pm-plugins/table-width.ts +4 -6
  213. package/src/toolbar.tsx +16 -19
  214. package/src/transforms/column-width.ts +7 -6
  215. package/src/transforms/delete-columns.ts +2 -2
  216. package/src/types.ts +1 -0
  217. package/src/ui/ColumnResizeWidget/index.tsx +2 -4
  218. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +11 -16
  219. package/src/ui/FloatingContextualMenu/index.tsx +0 -2
  220. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -3
  221. package/src/ui/FloatingDragMenu/index.tsx +4 -8
  222. package/src/ui/FloatingInsertButton/index.tsx +11 -22
  223. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +2 -2
  224. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +2 -2
  225. package/src/ui/TableFloatingColumnControls/index.tsx +2 -2
  226. package/src/utils/create.ts +2 -5
  227. package/src/utils/drag-menu.ts +8 -13
  228. package/src/utils/guidelines.ts +12 -1
  229. package/src/utils/snapping.ts +36 -0
@@ -39,7 +39,7 @@ export const scale = (
39
39
  tableRef: HTMLTableElement,
40
40
  options: ScaleOptions,
41
41
  domAtPos: DomAtPos,
42
- tablePreserveWidth = false,
42
+ isTableScalingEnabled = false,
43
43
  ): ResizeState | undefined => {
44
44
  /**
45
45
  * isBreakoutEnabled === true -> default center aligned
@@ -98,7 +98,7 @@ export const scale = (
98
98
  tableRef,
99
99
  start,
100
100
  domAtPos,
101
- tablePreserveWidth,
101
+ isTableScalingEnabled,
102
102
  });
103
103
 
104
104
  return scaleTableTo(resizeState, newWidth);
@@ -110,7 +110,7 @@ export const scaleWithParent = (
110
110
  table: PMNode,
111
111
  start: number,
112
112
  domAtPos: DomAtPos,
113
- tablePreserveWidth = false,
113
+ isTableScalingEnabled = false,
114
114
  ) => {
115
115
  const resizeState = getResizeState({
116
116
  minWidth: tableCellMinWidth,
@@ -119,7 +119,7 @@ export const scaleWithParent = (
119
119
  tableRef,
120
120
  start,
121
121
  domAtPos,
122
- tablePreserveWidth,
122
+ isTableScalingEnabled,
123
123
  });
124
124
 
125
125
  if (table.attrs.isNumberColumnEnabled) {
@@ -158,7 +158,7 @@ export const previewScaleTable = (
158
158
  tableRef: HTMLTableElement | null | undefined,
159
159
  options: ScaleOptions,
160
160
  domAtPos: DomAtPos,
161
- tablePreserveWidth: boolean = false,
161
+ isTableScalingEnabled: boolean = false,
162
162
  ) => {
163
163
  const { node, start, parentWidth } = options;
164
164
 
@@ -175,8 +175,8 @@ export const previewScaleTable = (
175
175
  }
176
176
 
177
177
  // If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
178
- // If we are scaling the table down with tablePreserveWidth, the colgroup widths may be scaled to a value that is not 48px.
179
- if (!hasTableBeenResized(node) && !tablePreserveWidth) {
178
+ // If we are scaling the table down with isTableScalingEnabled, the colgroup widths may be scaled to a value that is not 48px.
179
+ if (!hasTableBeenResized(node) && !isTableScalingEnabled) {
180
180
  syncStickyRowToTable(tableRef);
181
181
  return;
182
182
  }
@@ -188,12 +188,12 @@ export const previewScaleTable = (
188
188
  node,
189
189
  start,
190
190
  domAtPos,
191
- tablePreserveWidth,
191
+ isTableScalingEnabled,
192
192
  )
193
- : scale(tableRef, options, domAtPos, tablePreserveWidth);
193
+ : scale(tableRef, options, domAtPos, isTableScalingEnabled);
194
194
 
195
195
  if (resizeState) {
196
- updateColgroup(resizeState, tableRef, tablePreserveWidth);
196
+ updateColgroup(resizeState, tableRef, node, isTableScalingEnabled);
197
197
  }
198
198
  };
199
199
 
@@ -203,7 +203,7 @@ export const scaleTable =
203
203
  tableRef: HTMLTableElement | null | undefined,
204
204
  options: ScaleOptions,
205
205
  domAtPos: DomAtPos,
206
- tablePreserveWidth = false,
206
+ isTableScalingEnabled = false,
207
207
  ) =>
208
208
  (tr: Transaction) => {
209
209
  if (!tableRef) {
@@ -215,7 +215,7 @@ export const scaleTable =
215
215
  if (hasTableBeenResized(node) === false) {
216
216
  // If its not a re-sized table, we still want to re-create cols
217
217
  // To force reflow of columns upon delete.
218
- if (!tablePreserveWidth) {
218
+ if (!isTableScalingEnabled) {
219
219
  insertColgroupFromNode(tableRef, node);
220
220
  }
221
221
  tr.setMeta('scrollIntoView', false);
@@ -230,10 +230,10 @@ export const scaleTable =
230
230
  node,
231
231
  start,
232
232
  domAtPos,
233
- tablePreserveWidth,
233
+ isTableScalingEnabled,
234
234
  );
235
235
  } else {
236
- resizeState = scale(tableRef, options, domAtPos, tablePreserveWidth);
236
+ resizeState = scale(tableRef, options, domAtPos, isTableScalingEnabled);
237
237
  }
238
238
 
239
239
  if (resizeState) {
@@ -14,7 +14,6 @@ import {
14
14
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
15
15
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
16
16
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
17
- import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
18
17
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
19
18
  import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
20
19
  import {
@@ -24,6 +23,7 @@ import {
24
23
  } from '@atlaskit/editor-shared-styles';
25
24
  import { findTable } from '@atlaskit/editor-tables/utils';
26
25
 
26
+ import { getPluginState } from './plugin-factory';
27
27
  import { TABLE_MAX_WIDTH } from './table-resizing/utils';
28
28
 
29
29
  type __ReplaceStep = ReplaceStep & {
@@ -44,7 +44,6 @@ const createPlugin = (
44
44
  dispatch: Dispatch,
45
45
  dispatchAnalyticsEvent: DispatchAnalyticsEvent,
46
46
  fullWidthEnabled: boolean,
47
- getEditorFeatureFlags?: GetEditorFeatureFlags,
48
47
  ) => {
49
48
  return new SafePlugin({
50
49
  key: pluginKey,
@@ -123,10 +122,9 @@ const createPlugin = (
123
122
  tr.getMeta('referentialityTableInserted'),
124
123
  );
125
124
 
126
- const shouldPatchTable =
127
- fullWidthEnabled &&
128
- getEditorFeatureFlags &&
129
- getEditorFeatureFlags()['tablePreserveWidth'];
125
+ const { isTableScalingEnabled = false } = getPluginState(newState);
126
+
127
+ const shouldPatchTable = fullWidthEnabled && isTableScalingEnabled;
130
128
 
131
129
  if (
132
130
  !isReplaceDocumentOperation &&
package/src/toolbar.tsx CHANGED
@@ -169,7 +169,7 @@ export const getToolbarCellOptionsConfig = (
169
169
  { formatMessage }: ToolbarMenuContext,
170
170
  getEditorContainerWidth: GetEditorContainerWidth,
171
171
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
172
- tablePreserveWidth = false,
172
+ isTableScalingEnabled = false,
173
173
  ): FloatingToolbarDropdown<Command> => {
174
174
  const { top, bottom, right, left } = initialSelectionRect;
175
175
  const numberOfColumns = right - left;
@@ -188,11 +188,10 @@ export const getToolbarCellOptionsConfig = (
188
188
  const selectionRect = getClosestSelectionRect(state);
189
189
  const index = selectionRect?.right;
190
190
  if (index) {
191
- insertColumnWithAnalytics(
192
- getEditorContainerWidth,
193
- editorAnalyticsAPI,
194
- tablePreserveWidth,
195
- )(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
191
+ insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(
192
+ INPUT_METHOD.FLOATING_TB,
193
+ index,
194
+ )(state, dispatch, view);
196
195
  }
197
196
  return true;
198
197
  },
@@ -294,7 +293,7 @@ export const getToolbarCellOptionsConfig = (
294
293
  editorState,
295
294
  editorView.domAtPos.bind(editorView),
296
295
  getEditorContainerWidth,
297
- tablePreserveWidth,
296
+ isTableScalingEnabled,
298
297
  )
299
298
  : undefined;
300
299
  const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
@@ -462,19 +461,18 @@ export const getToolbarConfig =
462
461
  editorAnalyticsAPI,
463
462
  );
464
463
 
465
- const { tablePreserveWidth = false } = getEditorFeatureFlags();
464
+ const { isTableScalingEnabled = false } = getPluginState(state);
466
465
 
467
466
  let cellItems: Array<FloatingToolbarItem<Command>>;
468
467
  cellItems = pluginState.isDragAndDropEnabled
469
468
  ? []
470
469
  : getCellItems(
471
- config,
472
470
  state,
473
471
  getEditorView(),
474
472
  intl,
475
473
  getEditorContainerWidth,
476
474
  editorAnalyticsAPI,
477
- tablePreserveWidth,
475
+ isTableScalingEnabled,
478
476
  );
479
477
 
480
478
  let columnSettingsItems;
@@ -487,7 +485,7 @@ export const getToolbarConfig =
487
485
  intl,
488
486
  getEditorContainerWidth,
489
487
  editorAnalyticsAPI,
490
- tablePreserveWidth,
488
+ isTableScalingEnabled,
491
489
  )
492
490
  : [];
493
491
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
@@ -607,13 +605,12 @@ const separator = (hidden?: boolean): FloatingToolbarItem<Command> => {
607
605
  };
608
606
 
609
607
  const getCellItems = (
610
- pluginConfig: PluginConfig,
611
608
  state: EditorState,
612
609
  view: EditorView | null,
613
610
  { formatMessage }: ToolbarMenuContext,
614
611
  getEditorContainerWidth: GetEditorContainerWidth,
615
612
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
616
- tablePreserveWidth = false,
613
+ isTableScalingEnabled = false,
617
614
  ): Array<FloatingToolbarItem<Command>> => {
618
615
  const initialSelectionRect = getClosestSelectionRect(state);
619
616
  if (initialSelectionRect) {
@@ -624,7 +621,7 @@ const getCellItems = (
624
621
  { formatMessage },
625
622
  getEditorContainerWidth,
626
623
  editorAnalyticsAPI,
627
- tablePreserveWidth,
624
+ isTableScalingEnabled,
628
625
  );
629
626
  return [cellOptions, separator(cellOptions.hidden!)];
630
627
  }
@@ -635,7 +632,7 @@ export const getDistributeConfig =
635
632
  (
636
633
  getEditorContainerWidth: GetEditorContainerWidth,
637
634
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
638
- tablePreserveWidth = false,
635
+ isTableScalingEnabled = false,
639
636
  ): Command =>
640
637
  (state, dispatch, editorView) => {
641
638
  const selectionOrTableRect = getClosestSelectionOrTableRect(state);
@@ -647,7 +644,7 @@ export const getDistributeConfig =
647
644
  state,
648
645
  editorView.domAtPos.bind(editorView),
649
646
  getEditorContainerWidth,
650
- tablePreserveWidth,
647
+ isTableScalingEnabled,
651
648
  );
652
649
 
653
650
  if (newResizeStateWithAnalytics) {
@@ -668,7 +665,7 @@ const getColumnSettingItems = (
668
665
  { formatMessage }: ToolbarMenuContext,
669
666
  getEditorContainerWidth: GetEditorContainerWidth,
670
667
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
671
- tablePreserveWidth = false,
668
+ isTableScalingEnabled = false,
672
669
  ): Array<FloatingToolbarItem<Command>> => {
673
670
  const pluginState = getPluginState(editorState);
674
671
  const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
@@ -682,7 +679,7 @@ const getColumnSettingItems = (
682
679
  editorState,
683
680
  editorView.domAtPos.bind(editorView),
684
681
  getEditorContainerWidth,
685
- tablePreserveWidth,
682
+ isTableScalingEnabled,
686
683
  );
687
684
 
688
685
  const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
@@ -701,7 +698,7 @@ const getColumnSettingItems = (
701
698
  getDistributeConfig(
702
699
  getEditorContainerWidth,
703
700
  editorAnalyticsAPI,
704
- tablePreserveWidth,
701
+ isTableScalingEnabled,
705
702
  )(state, dispatch, view),
706
703
  disabled: !wouldChange,
707
704
  },
@@ -10,7 +10,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
10
10
 
11
11
  import type { ResizeState } from '../pm-plugins/table-resizing/utils';
12
12
  import {
13
- getTableContainerElement,
13
+ getTableContainerElementWidth,
14
14
  getTableElementWidth,
15
15
  hasTableBeenResized,
16
16
  } from '../pm-plugins/table-resizing/utils';
@@ -108,7 +108,7 @@ export const updateColumnWidths =
108
108
  * @returns Updated transaction with rescaled columns for a given table
109
109
  */
110
110
  export const rescaleColumns =
111
- (tablePreserveWidth = false) =>
111
+ (isTableScalingEnabled = false) =>
112
112
  (table: ContentNodeWithPos, view: EditorView | undefined) =>
113
113
  (tr: Transaction): Transaction => {
114
114
  if (!view) {
@@ -132,13 +132,14 @@ export const rescaleColumns =
132
132
  isResized,
133
133
  };
134
134
 
135
- if (tablePreserveWidth) {
135
+ if (isTableScalingEnabled) {
136
136
  previousTableInfo = {
137
137
  // TODO - ensure correct width is returned when table doesn't have a width value
138
138
  width: getTableElementWidth(table.node),
139
139
  possibleMaxWidth: getBooleanFF('platform.editor.custom-table-width')
140
- ? getTableContainerElement(table.node)
141
- : getTableContainerElement(table.node) - insertColumnButtonOffset,
140
+ ? getTableContainerElementWidth(table.node)
141
+ : getTableContainerElementWidth(table.node) -
142
+ insertColumnButtonOffset,
142
143
  isResized,
143
144
  };
144
145
  } else {
@@ -216,7 +217,7 @@ export const rescaleColumns =
216
217
  tableRef,
217
218
  domAtPos,
218
219
  maxSize: previousTableInfo.possibleMaxWidth,
219
- tablePreserveWidth,
220
+ isTableScalingEnabled,
220
221
  });
221
222
 
222
223
  // Two scenarios that require scaling:
@@ -253,7 +253,7 @@ export const deleteColumns =
253
253
  rect: Rect,
254
254
  allowCustomStep: boolean,
255
255
  view?: EditorView,
256
- tablePreserveWidth = false,
256
+ isTableScalingEnabled = false,
257
257
  ) =>
258
258
  (tr: Transaction) => {
259
259
  let updatedTr = tr;
@@ -269,7 +269,7 @@ export const deleteColumns =
269
269
  const table = findTable(updatedTr.selection);
270
270
 
271
271
  if (table) {
272
- updatedTr = rescaleColumns(tablePreserveWidth)(table, view)(updatedTr);
272
+ updatedTr = rescaleColumns(isTableScalingEnabled)(table, view)(updatedTr);
273
273
  }
274
274
  return updatedTr;
275
275
  };
package/src/types.ts CHANGED
@@ -138,6 +138,7 @@ export interface TablePluginState {
138
138
  isTableResizingEnabled?: boolean;
139
139
  isDragAndDropEnabled?: boolean;
140
140
  isTableHovered?: boolean;
141
+ isTableScalingEnabled?: boolean;
141
142
  }
142
143
 
143
144
  export type TablePluginAction =
@@ -1,6 +1,4 @@
1
1
  /** @jsx jsx */
2
- import React from 'react';
3
-
4
2
  import { jsx } from '@emotion/react';
5
3
  import { useIntl } from 'react-intl-next';
6
4
 
@@ -15,11 +13,11 @@ type Props = {
15
13
  includeTooltip?: boolean;
16
14
  };
17
15
 
18
- export const ColumnResizeWidget: React.FC<Props> = ({
16
+ export const ColumnResizeWidget = ({
19
17
  startIndex,
20
18
  endIndex,
21
19
  includeTooltip,
22
- }) => {
20
+ }: Props) => {
23
21
  const { formatMessage } = useIntl();
24
22
 
25
23
  if (!includeTooltip) {
@@ -468,14 +468,15 @@ export class ContextualMenu extends Component<
468
468
  (!isDragAndDropEnabled ||
469
469
  !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))
470
470
  ) {
471
- const { tablePreserveWidth = false } =
472
- this.props.getEditorFeatureFlags?.() || {};
471
+ const { isTableScalingEnabled = false } = getPluginState(
472
+ editorView.state,
473
+ );
473
474
  const newResizeState = getNewResizeStateFromSelectedColumns(
474
475
  selectionRect,
475
476
  editorView.state,
476
477
  editorView.domAtPos.bind(editorView),
477
478
  getEditorContainerWidth,
478
- tablePreserveWidth,
479
+ isTableScalingEnabled,
479
480
  );
480
481
 
481
482
  const wouldChange = newResizeState?.changed ?? false;
@@ -590,12 +591,11 @@ export class ContextualMenu extends Component<
590
591
  selectionRect,
591
592
  editorAnalyticsAPI,
592
593
  getEditorContainerWidth,
593
- getEditorFeatureFlags,
594
594
  } = this.props;
595
595
  // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
596
596
  const { state, dispatch } = editorView;
597
- const { targetCellPosition } = getPluginState(state);
598
- const { tablePreserveWidth = false } = getEditorFeatureFlags?.() || {};
597
+ const { targetCellPosition, isTableScalingEnabled = false } =
598
+ getPluginState(state);
599
599
 
600
600
  switch (item.value.name) {
601
601
  case 'sort_column_desc':
@@ -635,7 +635,7 @@ export class ContextualMenu extends Component<
635
635
  state,
636
636
  editorView.domAtPos.bind(editorView),
637
637
  getEditorContainerWidth,
638
- tablePreserveWidth,
638
+ isTableScalingEnabled,
639
639
  );
640
640
 
641
641
  if (newResizeStateWithAnalytics) {
@@ -654,15 +654,10 @@ export class ContextualMenu extends Component<
654
654
  this.toggleOpen();
655
655
  break;
656
656
  case 'insert_column':
657
- insertColumnWithAnalytics(
658
- getEditorContainerWidth,
659
- editorAnalyticsAPI,
660
- tablePreserveWidth,
661
- )(INPUT_METHOD.CONTEXT_MENU, selectionRect.right)(
662
- state,
663
- dispatch,
664
- editorView,
665
- );
657
+ insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(
658
+ INPUT_METHOD.CONTEXT_MENU,
659
+ selectionRect.right,
660
+ )(state, dispatch, editorView);
666
661
  this.toggleOpen();
667
662
  break;
668
663
  case 'insert_row':
@@ -53,7 +53,6 @@ const FloatingContextualMenu = ({
53
53
  pluginConfig,
54
54
  editorAnalyticsAPI,
55
55
  getEditorContainerWidth,
56
- getEditorFeatureFlags,
57
56
  }: Props) => {
58
57
  // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
59
58
  const { targetCellPosition, isDragAndDropEnabled } = getPluginState(
@@ -123,7 +122,6 @@ const FloatingContextualMenu = ({
123
122
  boundariesElement={boundariesElement}
124
123
  editorAnalyticsAPI={editorAnalyticsAPI}
125
124
  getEditorContainerWidth={getEditorContainerWidth}
126
- getEditorFeatureFlags={getEditorFeatureFlags}
127
125
  />
128
126
  </div>
129
127
  </Popup>
@@ -101,7 +101,7 @@ type DragMenuProps = {
101
101
  mountPoint?: HTMLElement;
102
102
  boundariesElement?: HTMLElement;
103
103
  scrollableElement?: HTMLElement;
104
- tablePreserveWidth?: boolean;
104
+ isTableScalingEnabled?: boolean;
105
105
  };
106
106
 
107
107
  type PluralOptionType = 'noOfCols' | 'noOfRows' | 'noOfCells' | null;
@@ -280,7 +280,7 @@ export const DragMenu = React.memo(
280
280
  mountPoint,
281
281
  scrollableElement,
282
282
  boundariesElement,
283
- tablePreserveWidth,
283
+ isTableScalingEnabled,
284
284
  }: DragMenuProps & WrappedComponentProps) => {
285
285
  const { state, dispatch } = editorView;
286
286
  const { selection } = state;
@@ -313,7 +313,7 @@ export const DragMenu = React.memo(
313
313
  selectionRect,
314
314
  editorAnalyticsAPI,
315
315
  pluginConfig?.isHeaderRowRequired,
316
- tablePreserveWidth,
316
+ isTableScalingEnabled,
317
317
  );
318
318
 
319
319
  const { menuItems, menuCallback } = convertToDropdownItems(
@@ -1,10 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
- import type {
5
- GetEditorContainerWidth,
6
- GetEditorFeatureFlags,
7
- } from '@atlaskit/editor-common/types';
4
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
8
5
  import { Popup } from '@atlaskit/editor-common/ui';
9
6
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
10
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -14,6 +11,7 @@ import {
14
11
  } from '@atlaskit/editor-shared-styles';
15
12
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
16
13
 
14
+ import { getPluginState } from '../../pm-plugins/plugin-factory';
17
15
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
18
16
  import type { PluginConfig, TableDirection } from '../../types';
19
17
  import { dragMenuDropdownWidth, tablePopupMenuFitHeight } from '../consts';
@@ -35,7 +33,6 @@ export interface Props {
35
33
  editorAnalyticsAPI?: EditorAnalyticsAPI;
36
34
  stickyHeaders?: RowStickyState;
37
35
  pluginConfig?: PluginConfig;
38
- getEditorFeatureFlags: GetEditorFeatureFlags;
39
36
  }
40
37
 
41
38
  const FloatingDragMenu = ({
@@ -52,7 +49,6 @@ const FloatingDragMenu = ({
52
49
  editorAnalyticsAPI,
53
50
  stickyHeaders,
54
51
  pluginConfig,
55
- getEditorFeatureFlags,
56
52
  }: Props) => {
57
53
  if (
58
54
  !isOpen ||
@@ -77,7 +73,7 @@ const FloatingDragMenu = ({
77
73
  return null;
78
74
  }
79
75
 
80
- const { tablePreserveWidth = false } = getEditorFeatureFlags();
76
+ const { isTableScalingEnabled = false } = getPluginState(editorView.state);
81
77
 
82
78
  return (
83
79
  <Popup
@@ -117,7 +113,7 @@ const FloatingDragMenu = ({
117
113
  mountPoint={mountPoint}
118
114
  boundariesElement={boundariesElement}
119
115
  scrollableElement={scrollableElement}
120
- tablePreserveWidth={tablePreserveWidth}
116
+ isTableScalingEnabled={isTableScalingEnabled}
121
117
  />
122
118
  </Popup>
123
119
  );
@@ -15,10 +15,7 @@ import {
15
15
  EVENT_TYPE,
16
16
  INPUT_METHOD,
17
17
  } from '@atlaskit/editor-common/analytics';
18
- import type {
19
- GetEditorContainerWidth,
20
- GetEditorFeatureFlags,
21
- } from '@atlaskit/editor-common/types';
18
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
22
19
  import { Popup } from '@atlaskit/editor-common/ui';
23
20
  import { closestElement } from '@atlaskit/editor-common/utils';
24
21
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
@@ -33,6 +30,7 @@ import {
33
30
  insertColumnWithAnalytics,
34
31
  insertRowWithAnalytics,
35
32
  } from '../../commands-with-analytics';
33
+ import { getPluginState } from '../../pm-plugins/plugin-factory';
36
34
  import { TableCssClassName as ClassName } from '../../types';
37
35
  import { checkIfNumberColumnEnabled } from '../../utils';
38
36
 
@@ -55,7 +53,6 @@ export interface Props {
55
53
  hasStickyHeaders?: boolean;
56
54
  dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
57
55
  editorAnalyticsAPI?: EditorAnalyticsAPI;
58
- getEditorFeatureFlags?: GetEditorFeatureFlags;
59
56
  }
60
57
 
61
58
  export class FloatingInsertButton extends React.Component<
@@ -278,29 +275,21 @@ export class FloatingInsertButton extends React.Component<
278
275
  }
279
276
 
280
277
  private insertColumn(event: React.SyntheticEvent) {
281
- const {
282
- editorView,
283
- insertColumnButtonIndex,
284
- editorAnalyticsAPI,
285
- getEditorContainerWidth,
286
- } = this.props;
278
+ const { editorView, insertColumnButtonIndex, editorAnalyticsAPI } =
279
+ this.props;
287
280
 
288
281
  if (typeof insertColumnButtonIndex !== 'undefined') {
289
282
  event.preventDefault();
290
283
 
291
- const { tablePreserveWidth = false } =
292
- this.props.getEditorFeatureFlags?.() || {};
284
+ const { isTableScalingEnabled = false } = getPluginState(
285
+ editorView.state,
286
+ );
293
287
 
294
288
  const { state, dispatch } = editorView;
295
- insertColumnWithAnalytics(
296
- getEditorContainerWidth,
297
- editorAnalyticsAPI,
298
- tablePreserveWidth,
299
- )(INPUT_METHOD.BUTTON, insertColumnButtonIndex)(
300
- state,
301
- dispatch,
302
- editorView,
303
- );
289
+ insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(
290
+ INPUT_METHOD.BUTTON,
291
+ insertColumnButtonIndex,
292
+ )(state, dispatch, editorView);
304
293
  }
305
294
  }
306
295
  }
@@ -13,13 +13,13 @@ export interface Props {
13
13
  marginTop?: number;
14
14
  }
15
15
 
16
- export const ColumnDropTarget: React.FC<Props> = ({
16
+ export const ColumnDropTarget = ({
17
17
  index,
18
18
  localId,
19
19
  width,
20
20
  height,
21
21
  marginTop,
22
- }) => {
22
+ }: Props) => {
23
23
  const dropTargetRef = useRef<HTMLDivElement | null>(null);
24
24
 
25
25
  useEffect(() => {
@@ -13,14 +13,14 @@ export interface Props {
13
13
  getScrollOffset?: () => number;
14
14
  }
15
15
 
16
- export const ColumnDropTargets: React.FC<Props> = ({
16
+ export const ColumnDropTargets = ({
17
17
  tableRef,
18
18
  tableHeight,
19
19
  localId,
20
20
  colWidths,
21
21
  isHeaderSticky,
22
22
  getScrollOffset,
23
- }) => {
23
+ }: Props) => {
24
24
  const dropTargetRef = useRef<HTMLDivElement>(null);
25
25
 
26
26
  if (!tableRef) {
@@ -40,7 +40,7 @@ export interface Props {
40
40
  getScrollOffset?: () => number;
41
41
  }
42
42
 
43
- export const TableFloatingColumnControls: React.FC<Props> = ({
43
+ export const TableFloatingColumnControls = ({
44
44
  editorView,
45
45
  tableRef,
46
46
  getNode,
@@ -55,7 +55,7 @@ export const TableFloatingColumnControls: React.FC<Props> = ({
55
55
  tableContainerWidth,
56
56
  isNumberColumnEnabled,
57
57
  getScrollOffset,
58
- }) => {
58
+ }: Props) => {
59
59
  const [tableRect, setTableRect] = useState<{ width: number; height: number }>(
60
60
  { width: 0, height: 0 },
61
61
  );
@@ -1,4 +1,3 @@
1
- import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
2
1
  import type { Schema } from '@atlaskit/editor-prosemirror/model';
3
2
  import { createTable } from '@atlaskit/editor-tables/utils';
4
3
 
@@ -6,17 +5,15 @@ import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
6
5
 
7
6
  export const createTableWithWidth =
8
7
  (
8
+ isTableScalingEnabled?: boolean,
9
9
  isFullWidthModeEnabled?: boolean,
10
- getEditorFeatureFlags?: GetEditorFeatureFlags,
11
10
  createTableProps?: {
12
11
  rowsCount?: number;
13
12
  colsCount?: number;
14
13
  },
15
14
  ) =>
16
15
  (schema: Schema) => {
17
- const { tablePreserveWidth = false } = getEditorFeatureFlags?.() || {};
18
-
19
- if (tablePreserveWidth && isFullWidthModeEnabled) {
16
+ if (isTableScalingEnabled && isFullWidthModeEnabled) {
20
17
  return createTable({
21
18
  schema,
22
19
  tableWidth: TABLE_MAX_WIDTH,