@atlaskit/editor-plugin-table 22.4.14 → 22.4.16

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 (213) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +2 -2
  3. package/dist/cjs/nodeviews/table.js +2 -2
  4. package/dist/cjs/nodeviews/toDOM.js +2 -2
  5. package/dist/cjs/pm-plugins/commands/active-table-menu.js +51 -0
  6. package/dist/cjs/pm-plugins/commands/commands-with-analytics.js +42 -10
  7. package/dist/cjs/pm-plugins/commands/index.js +13 -0
  8. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +2 -0
  9. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +4 -0
  10. package/dist/cjs/pm-plugins/handlers.js +8 -1
  11. package/dist/cjs/pm-plugins/main.js +4 -3
  12. package/dist/cjs/pm-plugins/reducer.js +2 -0
  13. package/dist/cjs/pm-plugins/table-width.js +2 -2
  14. package/dist/cjs/pm-plugins/transforms/content-mode.js +3 -2
  15. package/dist/cjs/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +70 -0
  16. package/dist/cjs/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +41 -0
  17. package/dist/cjs/pm-plugins/utils/tableMode/is-content-mode-supported.js +12 -0
  18. package/dist/cjs/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +113 -0
  19. package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/constants.js +10 -0
  20. package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +83 -0
  21. package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +56 -0
  22. package/dist/cjs/tablePlugin.js +1 -0
  23. package/dist/cjs/ui/ContentComponent.js +1 -1
  24. package/dist/cjs/ui/FloatingContextualButton/index.js +28 -9
  25. package/dist/cjs/ui/FloatingContextualMenu/CellMenuPopup.js +58 -73
  26. package/dist/cjs/ui/FloatingContextualMenu/index.js +26 -12
  27. package/dist/cjs/ui/FloatingDragMenu/index.js +21 -8
  28. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +13 -5
  29. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +14 -5
  30. package/dist/cjs/ui/TableMenu/cell/getCellMenuComponents.js +8 -3
  31. package/dist/cjs/ui/TableMenu/cell/items/MergeCellsItem.js +16 -1
  32. package/dist/cjs/ui/TableMenu/cell/items/SplitCellItem.js +16 -1
  33. package/dist/cjs/ui/TableMenu/column/items/AddColumnLeftItem.js +4 -4
  34. package/dist/cjs/ui/TableMenu/column/items/AddColumnRightItem.js +4 -4
  35. package/dist/cjs/ui/TableMenu/column/items/DeleteColumnItem.js +2 -3
  36. package/dist/cjs/ui/TableMenu/column/items/DistributeColumnsItem.js +2 -3
  37. package/dist/cjs/ui/TableMenu/column/items/HeaderColumnToggleItem.js +2 -3
  38. package/dist/cjs/ui/TableMenu/column/items/MoveColumnLeftItem.js +2 -3
  39. package/dist/cjs/ui/TableMenu/column/items/MoveColumnRightItem.js +2 -3
  40. package/dist/cjs/ui/TableMenu/column/items/SortDecreasingItem.js +2 -3
  41. package/dist/cjs/ui/TableMenu/column/items/SortIncreasingItem.js +2 -3
  42. package/dist/cjs/ui/TableMenu/row/items/AddRowAboveItem.js +4 -4
  43. package/dist/cjs/ui/TableMenu/row/items/AddRowBelowItem.js +4 -4
  44. package/dist/cjs/ui/TableMenu/row/items/DeleteRowItem.js +2 -3
  45. package/dist/cjs/ui/TableMenu/row/items/HeaderRowToggleItem.js +2 -3
  46. package/dist/cjs/ui/TableMenu/row/items/MoveRowDownItem.js +2 -3
  47. package/dist/cjs/ui/TableMenu/row/items/MoveRowUpItem.js +2 -3
  48. package/dist/cjs/ui/TableMenu/row/items/NumberedRowsToggleItem.js +4 -3
  49. package/dist/cjs/ui/TableMenu/shared/TableMenu.compiled.css +0 -2
  50. package/dist/cjs/ui/TableMenu/shared/TableMenu.js +8 -9
  51. package/dist/cjs/ui/TableMenu/shared/getSharedItems.js +3 -1
  52. package/dist/cjs/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
  53. package/dist/cjs/ui/TableMenu/shared/items/BackgroundColorItem.js +30 -4
  54. package/dist/cjs/ui/TableMenu/shared/items/ClearCellsItem.js +4 -3
  55. package/dist/cjs/ui/toolbar.js +4 -3
  56. package/dist/es2019/nodeviews/TableComponent.js +1 -1
  57. package/dist/es2019/nodeviews/table.js +1 -1
  58. package/dist/es2019/nodeviews/toDOM.js +1 -1
  59. package/dist/es2019/pm-plugins/commands/active-table-menu.js +39 -0
  60. package/dist/es2019/pm-plugins/commands/commands-with-analytics.js +31 -2
  61. package/dist/es2019/pm-plugins/commands/index.js +1 -0
  62. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +2 -0
  63. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +4 -0
  64. package/dist/es2019/pm-plugins/handlers.js +8 -1
  65. package/dist/es2019/pm-plugins/main.js +2 -1
  66. package/dist/es2019/pm-plugins/reducer.js +5 -0
  67. package/dist/es2019/pm-plugins/table-width.js +1 -1
  68. package/dist/es2019/pm-plugins/transforms/content-mode.js +2 -1
  69. package/dist/es2019/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +70 -0
  70. package/dist/es2019/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +38 -0
  71. package/dist/es2019/pm-plugins/utils/tableMode/is-content-mode-supported.js +7 -0
  72. package/dist/es2019/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +97 -0
  73. package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/constants.js +4 -0
  74. package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +63 -0
  75. package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +47 -0
  76. package/dist/es2019/tablePlugin.js +1 -0
  77. package/dist/es2019/ui/ContentComponent.js +1 -1
  78. package/dist/es2019/ui/FloatingContextualButton/index.js +29 -9
  79. package/dist/es2019/ui/FloatingContextualMenu/CellMenuPopup.js +60 -77
  80. package/dist/es2019/ui/FloatingContextualMenu/index.js +27 -12
  81. package/dist/es2019/ui/FloatingDragMenu/index.js +22 -8
  82. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -4
  83. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +13 -4
  84. package/dist/es2019/ui/TableMenu/cell/getCellMenuComponents.js +9 -3
  85. package/dist/es2019/ui/TableMenu/cell/items/MergeCellsItem.js +18 -2
  86. package/dist/es2019/ui/TableMenu/cell/items/SplitCellItem.js +18 -2
  87. package/dist/es2019/ui/TableMenu/column/items/AddColumnLeftItem.js +3 -3
  88. package/dist/es2019/ui/TableMenu/column/items/AddColumnRightItem.js +3 -3
  89. package/dist/es2019/ui/TableMenu/column/items/DeleteColumnItem.js +2 -3
  90. package/dist/es2019/ui/TableMenu/column/items/DistributeColumnsItem.js +2 -3
  91. package/dist/es2019/ui/TableMenu/column/items/HeaderColumnToggleItem.js +2 -3
  92. package/dist/es2019/ui/TableMenu/column/items/MoveColumnLeftItem.js +2 -3
  93. package/dist/es2019/ui/TableMenu/column/items/MoveColumnRightItem.js +2 -3
  94. package/dist/es2019/ui/TableMenu/column/items/SortDecreasingItem.js +2 -3
  95. package/dist/es2019/ui/TableMenu/column/items/SortIncreasingItem.js +2 -3
  96. package/dist/es2019/ui/TableMenu/row/items/AddRowAboveItem.js +3 -3
  97. package/dist/es2019/ui/TableMenu/row/items/AddRowBelowItem.js +3 -3
  98. package/dist/es2019/ui/TableMenu/row/items/DeleteRowItem.js +2 -3
  99. package/dist/es2019/ui/TableMenu/row/items/HeaderRowToggleItem.js +2 -3
  100. package/dist/es2019/ui/TableMenu/row/items/MoveRowDownItem.js +2 -3
  101. package/dist/es2019/ui/TableMenu/row/items/MoveRowUpItem.js +2 -3
  102. package/dist/es2019/ui/TableMenu/row/items/NumberedRowsToggleItem.js +3 -2
  103. package/dist/es2019/ui/TableMenu/shared/TableMenu.compiled.css +0 -2
  104. package/dist/es2019/ui/TableMenu/shared/TableMenu.js +8 -9
  105. package/dist/es2019/ui/TableMenu/shared/getSharedItems.js +3 -1
  106. package/dist/es2019/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
  107. package/dist/es2019/ui/TableMenu/shared/items/BackgroundColorItem.js +33 -4
  108. package/dist/es2019/ui/TableMenu/shared/items/ClearCellsItem.js +4 -3
  109. package/dist/es2019/ui/toolbar.js +2 -1
  110. package/dist/esm/nodeviews/TableComponent.js +1 -1
  111. package/dist/esm/nodeviews/table.js +1 -1
  112. package/dist/esm/nodeviews/toDOM.js +1 -1
  113. package/dist/esm/pm-plugins/commands/active-table-menu.js +45 -0
  114. package/dist/esm/pm-plugins/commands/commands-with-analytics.js +41 -10
  115. package/dist/esm/pm-plugins/commands/index.js +1 -0
  116. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +2 -0
  117. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +4 -0
  118. package/dist/esm/pm-plugins/handlers.js +8 -1
  119. package/dist/esm/pm-plugins/main.js +2 -1
  120. package/dist/esm/pm-plugins/reducer.js +2 -0
  121. package/dist/esm/pm-plugins/table-width.js +1 -1
  122. package/dist/esm/pm-plugins/transforms/content-mode.js +2 -1
  123. package/dist/esm/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +65 -0
  124. package/dist/esm/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +36 -0
  125. package/dist/esm/pm-plugins/utils/tableMode/is-content-mode-supported.js +6 -0
  126. package/dist/esm/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +107 -0
  127. package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/constants.js +4 -0
  128. package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +77 -0
  129. package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +49 -0
  130. package/dist/esm/tablePlugin.js +1 -0
  131. package/dist/esm/ui/ContentComponent.js +1 -1
  132. package/dist/esm/ui/FloatingContextualButton/index.js +29 -10
  133. package/dist/esm/ui/FloatingContextualMenu/CellMenuPopup.js +60 -75
  134. package/dist/esm/ui/FloatingContextualMenu/index.js +26 -12
  135. package/dist/esm/ui/FloatingDragMenu/index.js +21 -8
  136. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -4
  137. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +13 -4
  138. package/dist/esm/ui/TableMenu/cell/getCellMenuComponents.js +8 -3
  139. package/dist/esm/ui/TableMenu/cell/items/MergeCellsItem.js +16 -2
  140. package/dist/esm/ui/TableMenu/cell/items/SplitCellItem.js +16 -2
  141. package/dist/esm/ui/TableMenu/column/items/AddColumnLeftItem.js +4 -4
  142. package/dist/esm/ui/TableMenu/column/items/AddColumnRightItem.js +4 -4
  143. package/dist/esm/ui/TableMenu/column/items/DeleteColumnItem.js +2 -3
  144. package/dist/esm/ui/TableMenu/column/items/DistributeColumnsItem.js +2 -3
  145. package/dist/esm/ui/TableMenu/column/items/HeaderColumnToggleItem.js +2 -3
  146. package/dist/esm/ui/TableMenu/column/items/MoveColumnLeftItem.js +2 -3
  147. package/dist/esm/ui/TableMenu/column/items/MoveColumnRightItem.js +2 -3
  148. package/dist/esm/ui/TableMenu/column/items/SortDecreasingItem.js +2 -3
  149. package/dist/esm/ui/TableMenu/column/items/SortIncreasingItem.js +2 -3
  150. package/dist/esm/ui/TableMenu/row/items/AddRowAboveItem.js +4 -4
  151. package/dist/esm/ui/TableMenu/row/items/AddRowBelowItem.js +4 -4
  152. package/dist/esm/ui/TableMenu/row/items/DeleteRowItem.js +2 -3
  153. package/dist/esm/ui/TableMenu/row/items/HeaderRowToggleItem.js +2 -3
  154. package/dist/esm/ui/TableMenu/row/items/MoveRowDownItem.js +2 -3
  155. package/dist/esm/ui/TableMenu/row/items/MoveRowUpItem.js +2 -3
  156. package/dist/esm/ui/TableMenu/row/items/NumberedRowsToggleItem.js +4 -3
  157. package/dist/esm/ui/TableMenu/shared/TableMenu.compiled.css +0 -2
  158. package/dist/esm/ui/TableMenu/shared/TableMenu.js +8 -9
  159. package/dist/esm/ui/TableMenu/shared/getSharedItems.js +3 -1
  160. package/dist/esm/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
  161. package/dist/esm/ui/TableMenu/shared/items/BackgroundColorItem.js +30 -4
  162. package/dist/esm/ui/TableMenu/shared/items/ClearCellsItem.js +4 -3
  163. package/dist/esm/ui/toolbar.js +2 -1
  164. package/dist/types/entry-points/types.d.ts +1 -1
  165. package/dist/types/pm-plugins/commands/active-table-menu.d.ts +6 -0
  166. package/dist/types/pm-plugins/commands/commands-with-analytics.d.ts +3 -1
  167. package/dist/types/pm-plugins/commands/index.d.ts +1 -0
  168. package/dist/types/pm-plugins/transforms/content-mode.d.ts +1 -0
  169. package/dist/types/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.d.ts +8 -0
  170. package/dist/types/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.d.ts +6 -0
  171. package/dist/types/pm-plugins/utils/tableMode/is-content-mode-supported.d.ts +7 -0
  172. package/dist/types/pm-plugins/utils/tableMode/measure-table-with-auto-layout.d.ts +2 -0
  173. package/dist/types/pm-plugins/utils/tableMode/smart-adjust/constants.d.ts +4 -0
  174. package/dist/types/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.d.ts +8 -0
  175. package/dist/types/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.d.ts +7 -0
  176. package/dist/types/types/index.d.ts +21 -1
  177. package/dist/types/ui/FloatingContextualButton/index.d.ts +2 -0
  178. package/dist/types/ui/FloatingContextualMenu/CellMenuPopup.d.ts +7 -5
  179. package/dist/types/ui/FloatingContextualMenu/index.d.ts +0 -1
  180. package/dist/types/ui/TableMenu/cell/getCellMenuComponents.d.ts +2 -1
  181. package/dist/types/ui/TableMenu/cell/items/MergeCellsItem.d.ts +2 -1
  182. package/dist/types/ui/TableMenu/cell/items/SplitCellItem.d.ts +2 -1
  183. package/dist/types/ui/TableMenu/column/getColumnMenuComponents.d.ts +1 -1
  184. package/dist/types/ui/TableMenu/shared/TableMenuContext.d.ts +2 -0
  185. package/dist/types/ui/TableMenu/shared/items/BackgroundColorItem.d.ts +2 -1
  186. package/dist/types-ts4.5/entry-points/types.d.ts +1 -1
  187. package/dist/types-ts4.5/pm-plugins/commands/active-table-menu.d.ts +6 -0
  188. package/dist/types-ts4.5/pm-plugins/commands/commands-with-analytics.d.ts +3 -1
  189. package/dist/types-ts4.5/pm-plugins/commands/index.d.ts +1 -0
  190. package/dist/types-ts4.5/pm-plugins/transforms/content-mode.d.ts +1 -0
  191. package/dist/types-ts4.5/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.d.ts +8 -0
  192. package/dist/types-ts4.5/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.d.ts +6 -0
  193. package/dist/types-ts4.5/pm-plugins/utils/tableMode/is-content-mode-supported.d.ts +7 -0
  194. package/dist/types-ts4.5/pm-plugins/utils/tableMode/measure-table-with-auto-layout.d.ts +2 -0
  195. package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/constants.d.ts +4 -0
  196. package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.d.ts +8 -0
  197. package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.d.ts +7 -0
  198. package/dist/types-ts4.5/types/index.d.ts +21 -1
  199. package/dist/types-ts4.5/ui/FloatingContextualButton/index.d.ts +2 -0
  200. package/dist/types-ts4.5/ui/FloatingContextualMenu/CellMenuPopup.d.ts +7 -5
  201. package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +0 -1
  202. package/dist/types-ts4.5/ui/TableMenu/cell/getCellMenuComponents.d.ts +2 -1
  203. package/dist/types-ts4.5/ui/TableMenu/cell/items/MergeCellsItem.d.ts +2 -1
  204. package/dist/types-ts4.5/ui/TableMenu/cell/items/SplitCellItem.d.ts +2 -1
  205. package/dist/types-ts4.5/ui/TableMenu/column/getColumnMenuComponents.d.ts +1 -1
  206. package/dist/types-ts4.5/ui/TableMenu/shared/TableMenuContext.d.ts +2 -0
  207. package/dist/types-ts4.5/ui/TableMenu/shared/items/BackgroundColorItem.d.ts +2 -1
  208. package/package.json +10 -7
  209. package/dist/cjs/pm-plugins/utils/tableMode.js +0 -162
  210. package/dist/es2019/pm-plugins/utils/tableMode.js +0 -158
  211. package/dist/esm/pm-plugins/utils/tableMode.js +0 -156
  212. package/dist/types/pm-plugins/utils/tableMode.d.ts +0 -26
  213. package/dist/types-ts4.5/pm-plugins/utils/tableMode.d.ts +0 -26
@@ -0,0 +1,77 @@
1
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
+ import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
3
+ import { EVEN_SHARE_RATIO } from './constants';
4
+ export var sumWidths = function sumWidths(widths) {
5
+ return widths.reduce(function (sum, width) {
6
+ return sum + width;
7
+ }, 0);
8
+ };
9
+
10
+ // 2px absorbs sub-pixel rounding in `getRenderedColgroupColumnWidths`.
11
+ var SUB_PIXEL_ROUNDING_ALLOWANCE = 2;
12
+
13
+ /**
14
+ * Clamps each desired width to `[tableCellMinWidth, MAX × evenShare]`. Greedy
15
+ * columns (paragraphs) hit the ceiling and wrap; small columns stay at their
16
+ * natural width. Leftover canvas budget grows ceiling-hitters up to their
17
+ * desired; overflow reclaims from ceiling-hitters only.
18
+ */
19
+ export var distributeByEvenShareRatio = function distributeByEvenShareRatio(desiredWidths, editorContainerWidth) {
20
+ if (desiredWidths.length === 0 || !isFinite(editorContainerWidth) || editorContainerWidth <= 0) {
21
+ return desiredWidths;
22
+ }
23
+ var usableWidth = Math.max(editorContainerWidth - akEditorGutterPaddingDynamic() * 2, tableCellMinWidth * desiredWidths.length);
24
+ var evenShare = usableWidth / desiredWidths.length;
25
+ var ceiling = EVEN_SHARE_RATIO.MAX * evenShare;
26
+ var isCompactColumn = function isCompactColumn(width) {
27
+ return width <= ceiling;
28
+ };
29
+ var desiredCeil = desiredWidths.map(function (desired) {
30
+ return Math.max(tableCellMinWidth, Math.ceil(desired) + SUB_PIXEL_ROUNDING_ALLOWANCE);
31
+ });
32
+ var capped = desiredCeil.map(function (desired) {
33
+ return isCompactColumn(desired) ? desired : Math.min(ceiling, desired);
34
+ });
35
+ var sum = sumWidths(capped);
36
+
37
+ // Underflow: grow non-protected ceiling-hitters into the leftover, up to their desired.
38
+ if (sum < usableWidth) {
39
+ var leftover = usableWidth - sum;
40
+ var growthHeadroom = capped.map(function (width, index) {
41
+ return !isCompactColumn(desiredCeil[index]) && width >= ceiling ? Math.max(desiredCeil[index] - width, 0) : 0;
42
+ });
43
+ var totalHeadroom = sumWidths(growthHeadroom);
44
+ if (totalHeadroom > 0) {
45
+ var totalGrowth = Math.min(leftover, totalHeadroom);
46
+ return capped.map(function (width, index) {
47
+ var headroom = growthHeadroom[index];
48
+ if (headroom <= 0) {
49
+ return width;
50
+ }
51
+ return width + headroom / totalHeadroom * totalGrowth;
52
+ });
53
+ }
54
+ return capped;
55
+ }
56
+ if (sum === usableWidth) {
57
+ return capped;
58
+ }
59
+
60
+ // Overflow: reclaim from non-protected ceiling-hitters only.
61
+ var overage = sum - usableWidth;
62
+ var slacks = capped.map(function (width, index) {
63
+ return !isCompactColumn(desiredCeil[index]) && width >= ceiling ? Math.max(width - tableCellMinWidth, 0) : 0;
64
+ });
65
+ var totalSlack = sumWidths(slacks);
66
+ if (totalSlack <= 0) {
67
+ return capped;
68
+ }
69
+ return capped.map(function (width, index) {
70
+ var slack = slacks[index];
71
+ if (slack <= 0) {
72
+ return width;
73
+ }
74
+ var share = slack / totalSlack * Math.min(overage, totalSlack);
75
+ return Math.max(width - share, tableCellMinWidth);
76
+ });
77
+ };
@@ -0,0 +1,49 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { getTableMeasurement } from '../../../transforms/content-mode';
5
+ import { distributeByEvenShareRatio, sumWidths } from './distribute-column-widths';
6
+ var measureWithIntrinsicWidth = function measureWithIntrinsicWidth(tableRef, resizerContainer, resizerItem) {
7
+ if (resizerContainer) {
8
+ resizerContainer.style.width = 'var(--ak-editor-table-width)';
9
+ resizerContainer.style.setProperty('--ak-editor-table-width', 'max-content');
10
+ }
11
+ if (resizerItem) {
12
+ resizerItem.style.width = 'max-content';
13
+ }
14
+ var prevTableWidth = tableRef.style.width;
15
+ var prevTableMaxWidth = tableRef.style.maxWidth;
16
+ var prevTableMinWidth = tableRef.style.minWidth;
17
+ tableRef.style.setProperty('width', 'max-content', 'important');
18
+ tableRef.style.setProperty('max-width', 'none', 'important');
19
+ tableRef.style.setProperty('min-width', '0', 'important');
20
+ try {
21
+ return getTableMeasurement(tableRef);
22
+ } finally {
23
+ tableRef.style.width = prevTableWidth;
24
+ tableRef.style.maxWidth = prevTableMaxWidth;
25
+ tableRef.style.minWidth = prevTableMinWidth;
26
+ }
27
+ };
28
+ export var restoreResizerContainer = function restoreResizerContainer(resizerContainer) {
29
+ if (!resizerContainer) {
30
+ return;
31
+ }
32
+ resizerContainer.style.width = 'var(--ak-editor-table-width)';
33
+ resizerContainer.style.removeProperty('--ak-editor-table-width');
34
+ };
35
+
36
+ /**
37
+ * Smart-adjust: measure unconstrained max-content per column, then clamp via
38
+ * `distributeByEvenShareRatio`.
39
+ */
40
+ export var runSmartAdjust = function runSmartAdjust(tableRef, resizerContainer, resizerItem, editorContainerWidthFromApi) {
41
+ var preferredMeasurement = measureWithIntrinsicWidth(tableRef, resizerContainer, resizerItem);
42
+ var desiredWidths = preferredMeasurement.colWidths;
43
+ var editorContainerWidth = editorContainerWidthFromApi !== null && editorContainerWidthFromApi !== void 0 ? editorContainerWidthFromApi : sumWidths(desiredWidths);
44
+ var colWidths = distributeByEvenShareRatio(desiredWidths, editorContainerWidth);
45
+ return _objectSpread(_objectSpread({}, preferredMeasurement), {}, {
46
+ colWidths: colWidths,
47
+ tableWidth: sumWidths(colWidths)
48
+ });
49
+ };
@@ -143,6 +143,7 @@ var tablePlugin = function tablePlugin(_ref) {
143
143
  insertRowButtonIndex: tablePluginState.insertRowButtonIndex,
144
144
  tableWrapperTarget: tablePluginState.tableWrapperTarget,
145
145
  isCellMenuOpenByKeyboard: tablePluginState.isCellMenuOpenByKeyboard,
146
+ activeTableMenu: tablePluginState.activeTableMenu,
146
147
  stickyHeader: stickyHeader,
147
148
  dragMenuDirection: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuDirection,
148
149
  dragMenuIndex: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuIndex,
@@ -90,6 +90,7 @@ var ContentComponentInternal = function ContentComponentInternal(_ref) {
90
90
  return null;
91
91
  }
92
92
  return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
93
+ api: api,
93
94
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
94
95
  editorView: editorView,
95
96
  tableNode: tableNode,
@@ -125,7 +126,6 @@ var ContentComponentInternal = function ContentComponentInternal(_ref) {
125
126
  editorView: editorView,
126
127
  mountPoint: popupsMountPoint,
127
128
  boundariesElement: popupsBoundariesElement,
128
- targetCellPosition: targetCellPosition,
129
129
  isOpen: Boolean(isContextualMenuOpen) && !isResizing,
130
130
  pluginConfig: pluginConfig,
131
131
  editorAnalyticsAPI: editorAnalyticsAPI,
@@ -8,6 +8,7 @@ import { css, jsx } from '@emotion/react';
8
8
  import { injectIntl } from 'react-intl';
9
9
  import { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
10
10
  import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
11
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
11
12
  import { focusToContextMenuTrigger } from '@atlaskit/editor-common/keymaps';
12
13
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
13
14
  import { Popup } from '@atlaskit/editor-common/ui';
@@ -17,7 +18,7 @@ import { akEditorSmallZIndex } from '@atlaskit/editor-shared-styles';
17
18
  import ExpandIcon from '@atlaskit/icon/core/chevron-down';
18
19
  import { fg } from '@atlaskit/platform-feature-flags';
19
20
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
20
- import { toggleContextualMenu } from '../../pm-plugins/commands';
21
+ import { toggleActiveTableMenu, toggleContextualMenu } from '../../pm-plugins/commands';
21
22
  import { isNativeStickySupported } from '../../pm-plugins/utils/sticky-header';
22
23
  import { TableCssClassName as ClassName } from '../../types';
23
24
 
@@ -33,7 +34,8 @@ var anchorStyles = css({
33
34
  zIndex: CONTEXTUAL_MENU_BUTTON_Z_INDEX
34
35
  });
35
36
  var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
36
- var editorView = props.editorView,
37
+ var api = props.api,
38
+ editorView = props.editorView,
37
39
  isContextualMenuOpen = props.isContextualMenuOpen,
38
40
  mountPoint = props.mountPoint,
39
41
  scrollableElement = props.scrollableElement,
@@ -42,12 +44,22 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
42
44
  targetCellPosition = props.targetCellPosition,
43
45
  isCellMenuOpenByKeyboard = props.isCellMenuOpenByKeyboard,
44
46
  formatMessage = props.intl.formatMessage; // : Props & WrappedComponentProps
45
-
47
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['table'], function (states) {
48
+ var _states$tableState;
49
+ return {
50
+ activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
51
+ };
52
+ }),
53
+ activeTableMenu = _useSharedPluginState.activeTableMenu;
54
+ var isCellMenuOpen = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'cell' : isContextualMenuOpen;
46
55
  var handleClick = function handleClick() {
47
56
  var state = editorView.state,
48
57
  dispatch = editorView.dispatch;
49
58
  if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
50
- toggleContextualMenu()(state, dispatch);
59
+ toggleActiveTableMenu({
60
+ type: 'cell',
61
+ openedBy: 'mouse'
62
+ })(state, dispatch);
51
63
  return;
52
64
  }
53
65
 
@@ -63,13 +75,20 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
63
75
  var domAtPos = editorView.domAtPos.bind(editorView);
64
76
  var targetCellRef = findDomRefAtPos(targetCellPosition, domAtPos);
65
77
  useEffect(function () {
66
- if (isCellMenuOpenByKeyboard && !isContextualMenuOpen) {
78
+ if (isCellMenuOpenByKeyboard && !isCellMenuOpen) {
67
79
  var state = editorView.state,
68
80
  dispatch = editorView.dispatch;
69
81
  // open the menu when the keyboard shortcut is pressed
82
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
83
+ toggleActiveTableMenu({
84
+ type: 'cell',
85
+ openedBy: 'keyboard'
86
+ })(state, dispatch);
87
+ return;
88
+ }
70
89
  toggleContextualMenu()(state, dispatch);
71
90
  }
72
- }, [isCellMenuOpenByKeyboard, isContextualMenuOpen, editorView]);
91
+ }, [isCellMenuOpenByKeyboard, isCellMenuOpen, editorView]);
73
92
  if (!targetCellRef || !(targetCellRef instanceof HTMLElement)) {
74
93
  return null;
75
94
  }
@@ -79,12 +98,12 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
79
98
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
80
99
  tableFloatingCellButtonStyles(),
81
100
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
82
- isContextualMenuOpen && tableFloatingCellButtonSelectedStyles()]
101
+ isCellMenuOpen && tableFloatingCellButtonSelectedStyles()]
83
102
  }, jsx(ToolbarButton
84
103
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
85
104
  , {
86
105
  className: ClassName.CONTEXTUAL_MENU_BUTTON,
87
- selected: isContextualMenuOpen,
106
+ selected: isCellMenuOpen,
88
107
  title: labelCellOptions,
89
108
  keymap: focusToContextMenuTrigger,
90
109
  onClick: handleClick,
@@ -94,7 +113,7 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
94
113
  size: "small"
95
114
  }),
96
115
  "aria-label": labelCellOptions,
97
- "aria-expanded": isContextualMenuOpen
116
+ "aria-expanded": isCellMenuOpen
98
117
  }));
99
118
  var parentSticky = targetCellRef.parentElement && targetCellRef.parentElement.className.indexOf('sticky') > -1;
100
119
  var parentStickyNative = targetCellRef.parentElement && (fg('platform_editor_table_sticky_header_patch_4') ? tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.classList.contains(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW) : targetCellRef.parentElement.classList.contains(ClassName.NATIVE_STICKY));
@@ -149,7 +168,7 @@ var FloatingContextualButtonInner = /*#__PURE__*/React.memo(function (props) {
149
168
  targetCellPosition: targetCellPosition,
150
169
  targetCellRef: targetCellRef,
151
170
  mountTo: tableWrapper,
152
- isContextualMenuOpen: isContextualMenuOpen
171
+ isContextualMenuOpen: isCellMenuOpen
153
172
  }, button);
154
173
  }
155
174
  return jsx(Popup, {
@@ -1,96 +1,81 @@
1
- import React, { useCallback, useEffect, useRef } from 'react';
2
- import { bind } from 'bind-event-listener';
3
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
1
+ import React, { useCallback, useContext, useRef } from 'react';
2
+ import { Popup } from '@atlaskit/editor-common/ui';
3
+ import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
4
4
  import { UserIntentPopupWrapper } from '@atlaskit/editor-common/user-intent';
5
- import { setFocusToCellMenu, toggleContextualMenu } from '../../pm-plugins/commands';
5
+ import { closeActiveTableMenu, setFocusToCellMenu } from '../../pm-plugins/commands';
6
+ import { getPluginState } from '../../pm-plugins/plugin-factory';
6
7
  import { TableCssClassName as ClassName } from '../../types';
8
+ import { tablePopupMenuFitHeight } from '../consts';
7
9
  import { CELL_MENU } from '../TableMenu/cell/keys';
10
+ import { TABLE_MENU_WIDTH } from '../TableMenu/shared/consts';
8
11
  import { TableMenu } from '../TableMenu/shared/TableMenu';
12
+ var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
13
+ var NESTED_DROPDOWN_SELECTOR = '[data-toolbar-nested-dropdown-menu]';
14
+ var CELL_MENU_TRIGGER_SELECTOR = ".".concat(ClassName.CONTEXTUAL_MENU_BUTTON);
9
15
  export var CellMenuPopup = function CellMenuPopup(_ref) {
10
16
  var api = _ref.api,
17
+ boundariesElement = _ref.boundariesElement,
11
18
  editorView = _ref.editorView,
12
- isCellMenuOpenByKeyboard = _ref.isCellMenuOpenByKeyboard,
13
- isOpen = _ref.isOpen,
14
- targetCellRef = _ref.targetCellRef;
15
- var tableMenuRef = useRef(null);
16
- var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['userIntent'], function (states) {
17
- var _states$userIntentSta;
18
- return {
19
- currentUserIntent: (_states$userIntentSta = states.userIntentState) === null || _states$userIntentSta === void 0 ? void 0 : _states$userIntentSta.currentUserIntent
20
- };
21
- }),
22
- currentUserIntent = _useSharedPluginState.currentUserIntent;
19
+ mountPoint = _ref.mountPoint,
20
+ scrollableElement = _ref.scrollableElement,
21
+ targetCellRef = _ref.targetCellRef,
22
+ zIndex = _ref.zIndex;
23
+ var popupContentRef = useRef(null);
24
+ var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
25
+ var handlePopupRef = useCallback(function (el) {
26
+ popupContentRef.current = el;
27
+ setOutsideClickTargetRef === null || setOutsideClickTargetRef === void 0 || setOutsideClickTargetRef(el);
28
+ }, [setOutsideClickTargetRef]);
23
29
  var closeCellMenu = useCallback(function () {
24
- var state = editorView.state,
25
- dispatch = editorView.dispatch,
26
- dom = editorView.dom;
27
- toggleContextualMenu()(state, dispatch);
30
+ var _getPluginState = getPluginState(editorView.state),
31
+ isCellMenuOpenByKeyboard = _getPluginState.isCellMenuOpenByKeyboard;
32
+ closeActiveTableMenu()(editorView.state, editorView.dispatch);
28
33
  if (isCellMenuOpenByKeyboard) {
29
- setFocusToCellMenu(false)(state, dispatch);
30
- dom.focus();
34
+ setFocusToCellMenu(false)(editorView.state, editorView.dispatch);
31
35
  }
32
- }, [editorView, isCellMenuOpenByKeyboard]);
33
- useEffect(function () {
34
- if (!isOpen || currentUserIntent !== 'tableDragMenuPopupOpen') {
35
- return;
36
+ }, [editorView]);
37
+ var isEventInsideCellMenu = useCallback(function (event) {
38
+ var _popupContentRef$curr;
39
+ var target = event.target;
40
+ if (!(target instanceof Node)) {
41
+ return false;
36
42
  }
37
- closeCellMenu();
38
- }, [closeCellMenu, currentUserIntent, isOpen]);
39
- useEffect(function () {
40
- if (!isOpen) {
41
- return;
43
+ if ((_popupContentRef$curr = popupContentRef.current) !== null && _popupContentRef$curr !== void 0 && _popupContentRef$curr.contains(target)) {
44
+ return true;
42
45
  }
43
- if (!(targetCellRef instanceof HTMLElement)) {
46
+ return target instanceof Element && Boolean(target.closest(NESTED_DROPDOWN_SELECTOR) || target.closest(CELL_MENU_TRIGGER_SELECTOR));
47
+ }, []);
48
+ var handleCellMenuClickOutside = useCallback(function (event) {
49
+ if (isEventInsideCellMenu(event)) {
44
50
  return;
45
51
  }
46
- var ownerDocument = targetCellRef.ownerDocument;
47
- var handlePointerDown = function handlePointerDown(event) {
48
- var _tableMenuRef$current;
49
- var target = event.target;
50
- if (!(target instanceof Node)) {
51
- return;
52
- }
53
- if ((_tableMenuRef$current = tableMenuRef.current) !== null && _tableMenuRef$current !== void 0 && _tableMenuRef$current.contains(target)) {
54
- return;
55
- }
56
- var cellMenuButton = ownerDocument.querySelector(".".concat(ClassName.CONTEXTUAL_MENU_BUTTON));
57
- if (cellMenuButton !== null && cellMenuButton !== void 0 && cellMenuButton.contains(target)) {
58
- return;
59
- }
60
- closeCellMenu();
61
- };
62
- var handleKeyDown = function handleKeyDown(event) {
63
- if (event.key === 'Escape') {
64
- closeCellMenu();
65
- }
66
- };
67
- var unbindPointerDown = bind(ownerDocument, {
68
- type: 'pointerdown',
69
- listener: handlePointerDown,
70
- options: {
71
- capture: true
72
- }
73
- });
74
- var unbindKeyDown = bind(ownerDocument, {
75
- type: 'keydown',
76
- listener: handleKeyDown,
77
- options: {
78
- capture: true
79
- }
80
- });
81
- return function () {
82
- unbindPointerDown();
83
- unbindKeyDown();
84
- };
85
- }, [closeCellMenu, isOpen, targetCellRef]);
86
- return /*#__PURE__*/React.createElement(UserIntentPopupWrapper, {
52
+ closeCellMenu();
53
+ }, [closeCellMenu, isEventInsideCellMenu]);
54
+ return /*#__PURE__*/React.createElement(PopupWithListeners, {
55
+ alignX: "right",
56
+ alignY: "top",
57
+ target: targetCellRef,
58
+ mountTo: mountPoint,
59
+ boundariesElement: boundariesElement,
60
+ scrollableElement: scrollableElement,
61
+ fitHeight: tablePopupMenuFitHeight,
62
+ fitWidth: TABLE_MENU_WIDTH,
63
+ zIndex: zIndex,
64
+ forcePlacement: true
65
+ // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
66
+ ,
67
+ offset: [-7, 0],
68
+ stick: true,
69
+ handleClickOutside: handleCellMenuClickOutside,
70
+ handleEscapeKeydown: closeCellMenu
71
+ }, /*#__PURE__*/React.createElement("div", {
72
+ ref: handlePopupRef
73
+ }, /*#__PURE__*/React.createElement(UserIntentPopupWrapper, {
87
74
  api: api,
88
75
  userIntent: "tableContextualMenuPopupOpen"
89
- }, /*#__PURE__*/React.createElement("div", {
90
- ref: tableMenuRef
91
76
  }, /*#__PURE__*/React.createElement(TableMenu, {
92
77
  api: api,
93
78
  editorView: editorView,
94
79
  surface: CELL_MENU
95
- })));
80
+ }))));
96
81
  };
@@ -4,6 +4,7 @@
4
4
  */
5
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
6
  import { jsx } from '@emotion/react';
7
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
7
8
  import { Popup } from '@atlaskit/editor-common/ui';
8
9
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
9
10
  import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
@@ -11,7 +12,6 @@ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@at
11
12
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
13
  import { getPluginState } from '../../pm-plugins/plugin-factory';
13
14
  import { contextualMenuDropdownWidthDnD, contextualMenuTriggerSize, tablePopupMenuFitHeight } from '../consts';
14
- import { TABLE_MENU_WIDTH } from '../TableMenu/shared/consts';
15
15
  import { CellMenuPopup } from './CellMenuPopup';
16
16
  // Ignored via go/ees005
17
17
  // eslint-disable-next-line import/no-named-as-default
@@ -31,6 +31,14 @@ var FloatingContextualMenu = function FloatingContextualMenu(_ref) {
31
31
  isCommentEditor = _ref.isCommentEditor,
32
32
  api = _ref.api,
33
33
  isDragMenuOpen = _ref.isDragMenuOpen;
34
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['table'], function (states) {
35
+ var _states$tableState;
36
+ return {
37
+ activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
38
+ };
39
+ }),
40
+ activeTableMenu = _useSharedPluginState.activeTableMenu;
41
+ var isCellMenuOpen = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'cell' : isOpen;
34
42
  if (!editorView) {
35
43
  return null;
36
44
  }
@@ -38,7 +46,7 @@ var FloatingContextualMenu = function FloatingContextualMenu(_ref) {
38
46
  // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
39
47
  var _getPluginState = getPluginState(editorView.state),
40
48
  targetCellPosition = _getPluginState.targetCellPosition;
41
- if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
49
+ if (!isCellMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
42
50
  return null;
43
51
  }
44
52
  var selection = editorView.state.selection;
@@ -55,6 +63,20 @@ var FloatingContextualMenu = function FloatingContextualMenu(_ref) {
55
63
  return null;
56
64
  }
57
65
  var parentSticky = targetCellRef.parentElement && targetCellRef.parentElement.className.indexOf('sticky') > -1;
66
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
67
+ return jsx(CellMenuPopup, {
68
+ api: api,
69
+ boundariesElement: boundariesElement,
70
+ editorView: editorView,
71
+ mountPoint: mountPoint,
72
+ scrollableElement: scrollableElement
73
+ // Ignored via go/ees005
74
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
75
+ ,
76
+ targetCellRef: targetCellRef,
77
+ zIndex: parentSticky ? akEditorFloatingDialogZIndex : akEditorFloatingOverlapPanelZIndex
78
+ });
79
+ }
58
80
  return jsx(Popup, {
59
81
  alignX: "right",
60
82
  alignY: "top"
@@ -66,7 +88,7 @@ var FloatingContextualMenu = function FloatingContextualMenu(_ref) {
66
88
  boundariesElement: boundariesElement,
67
89
  scrollableElement: scrollableElement,
68
90
  fitHeight: tablePopupMenuFitHeight,
69
- fitWidth: expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? TABLE_MENU_WIDTH : contextualMenuDropdownWidthDnD
91
+ fitWidth: contextualMenuDropdownWidthDnD
70
92
  // z-index value below is to ensure that this menu is above other floating menu
71
93
  // in table, but below floating dialogs like typeaheads, pickers, etc.
72
94
  ,
@@ -76,15 +98,7 @@ var FloatingContextualMenu = function FloatingContextualMenu(_ref) {
76
98
  ,
77
99
  offset: [-7, 0],
78
100
  stick: true
79
- }, expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? jsx(CellMenuPopup, {
80
- api: api,
81
- editorView: editorView,
82
- isCellMenuOpenByKeyboard: isCellMenuOpenByKeyboard,
83
- isOpen: isOpen,
84
- targetCellRef: targetCellRef
85
- }) :
86
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
87
- jsx("div", {
101
+ }, jsx("div", {
88
102
  css: tablePopupStyles()
89
103
  }, jsx(ContextualMenu, {
90
104
  editorView: editorView
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
2
3
  import { Popup } from '@atlaskit/editor-common/ui';
3
4
  import { UserIntentPopupWrapper } from '@atlaskit/editor-common/user-intent';
4
5
  import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
@@ -34,11 +35,23 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
34
35
  api = _ref.api,
35
36
  isCommentEditor = _ref.isCommentEditor,
36
37
  tableWrapper = _ref.tableWrapper;
37
- if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
38
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['table'], function (states) {
39
+ var _states$tableState;
40
+ return {
41
+ activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
42
+ };
43
+ }),
44
+ activeTableMenu = _useSharedPluginState.activeTableMenu;
45
+ var isActiveTableMenuDragMenu = (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'row' || (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'column';
46
+ var hasActiveTableMenuState = activeTableMenu !== undefined;
47
+ var isDragMenuOpen = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu : isOpen;
48
+ var dragMenuDirection = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu ? activeTableMenu.type : undefined : direction;
49
+ var dragMenuIndex = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu ? activeTableMenu.index : undefined : index;
50
+ if (!isDragMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
38
51
  return null;
39
52
  }
40
53
  var inStickyMode = (stickyHeaders === null || stickyHeaders === void 0 ? void 0 : stickyHeaders.sticky) || (tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.classList.contains(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW)) && fg('platform_editor_table_sticky_header_patch_7');
41
- var targetHandleRef = direction === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
54
+ var targetHandleRef = dragMenuDirection === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
42
55
  if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
43
56
  return null;
44
57
  }
@@ -47,8 +60,8 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
47
60
  tableWithFixedColumnWidthsOption = _ref2$tableWithFixedC === void 0 ? false : _ref2$tableWithFixedC;
48
61
  var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (tableWithFixedColumnWidthsOption || isCommentEditor);
49
62
  return /*#__PURE__*/React.createElement(Popup, {
50
- alignX: direction === 'row' ? 'right' : undefined,
51
- alignY: direction === 'row' ? 'start' : undefined
63
+ alignX: dragMenuDirection === 'row' ? 'right' : undefined,
64
+ alignY: dragMenuDirection === 'row' ? 'start' : undefined
52
65
  // Ignored via go/ees005
53
66
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
54
67
  ,
@@ -72,13 +85,13 @@ var FloatingDragMenu = function FloatingDragMenu(_ref) {
72
85
  }, /*#__PURE__*/React.createElement(TableMenu, {
73
86
  api: api,
74
87
  editorView: editorView,
75
- surface: direction === 'row' ? ROW_MENU : COLUMN_MENU
88
+ surface: dragMenuDirection === 'row' ? ROW_MENU : COLUMN_MENU
76
89
  })) : /*#__PURE__*/React.createElement(DragMenu, {
77
90
  editorView: editorView,
78
- isOpen: isOpen,
91
+ isOpen: isDragMenuOpen,
79
92
  tableNode: tableNode,
80
- direction: direction,
81
- index: index,
93
+ direction: dragMenuDirection,
94
+ index: dragMenuIndex,
82
95
  target: targetHandleRef || undefined,
83
96
  targetCellPosition: targetCellPosition,
84
97
  getEditorContainerWidth: getEditorContainerWidth,
@@ -8,6 +8,7 @@ import { CellSelection } from '@atlaskit/editor-tables';
8
8
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
9
9
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
10
  import { clearHoverSelection, hoverCell, hoverColumns, selectColumn, selectColumns } from '../../../pm-plugins/commands';
11
+ import { toggleActiveTableMenuWithAnalytics } from '../../../pm-plugins/commands/commands-with-analytics';
11
12
  import { toggleDragMenuWithAnalytics } from '../../../pm-plugins/drag-and-drop/commands-with-analytics';
12
13
  import { getRowsParams } from '../../../pm-plugins/utils/row-controls';
13
14
  import { getSelectedColumnIndexes } from '../../../pm-plugins/utils/selection';
@@ -24,7 +25,7 @@ var getSelectedColumns = function getSelectedColumns(selection) {
24
25
  return [];
25
26
  };
26
27
  export var ColumnControls = function ColumnControls(_ref) {
27
- var _colWidths$map$join, _api$analytics2;
28
+ var _colWidths$map$join, _api$analytics3;
28
29
  var editorView = _ref.editorView,
29
30
  tableActive = _ref.tableActive,
30
31
  tableRef = _ref.tableRef,
@@ -117,14 +118,21 @@ export var ColumnControls = function ColumnControls(_ref) {
117
118
  }
118
119
  }, [editorView, tableActive]);
119
120
  var toggleDragMenuHandler = useCallback(function (trigger, event) {
120
- var _api$analytics;
121
+ var _api$analytics2;
121
122
  var state = editorView.state,
122
123
  dispatch = editorView.dispatch;
123
124
  if (event !== null && event !== void 0 && event.shiftKey) {
124
125
  return;
125
126
  }
126
- toggleDragMenuWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(undefined, 'column', colIndex, trigger)(state, dispatch);
127
- }, [editorView, colIndex, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions]);
127
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
128
+ if (colIndex !== undefined) {
129
+ var _api$analytics;
130
+ toggleActiveTableMenuWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)('column', colIndex, trigger)(state, dispatch);
131
+ }
132
+ return;
133
+ }
134
+ toggleDragMenuWithAnalytics(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(undefined, 'column', colIndex, trigger)(state, dispatch);
135
+ }, [editorView, colIndex, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions]);
128
136
  var colIndexes = useMemo(function () {
129
137
  // Ignored via go/ees005
130
138
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -8,6 +8,7 @@ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
8
8
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
9
9
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
10
  import { clearHoverSelection } from '../../../pm-plugins/commands';
11
+ import { toggleActiveTableMenuWithAnalytics } from '../../../pm-plugins/commands/commands-with-analytics';
11
12
  import { toggleDragMenuWithAnalytics } from '../../../pm-plugins/drag-and-drop/commands-with-analytics';
12
13
  import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
13
14
  import { getRowHeights, getRowsParams } from '../../../pm-plugins/utils/row-controls';
@@ -27,7 +28,7 @@ var getSelectedRows = function getSelectedRows(selection) {
27
28
  return [];
28
29
  };
29
30
  export var DragControls = function DragControls(_ref) {
30
- var _tableNode$attrs$loca, _tableNode$attrs, _api$analytics2;
31
+ var _tableNode$attrs$loca, _tableNode$attrs, _api$analytics3;
31
32
  var tableRef = _ref.tableRef,
32
33
  tableNode = _ref.tableNode,
33
34
  tableWidth = _ref.tableWidth,
@@ -80,12 +81,20 @@ export var DragControls = function DragControls(_ref) {
80
81
  });
81
82
  }, [editorView]);
82
83
  var toggleDragMenuHandler = useCallback(function (trigger, event) {
83
- var _api$analytics;
84
+ var _api$analytics2;
84
85
  if (event !== null && event !== void 0 && event.shiftKey) {
85
86
  return;
86
87
  }
87
- toggleDragMenuWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(undefined, 'row', hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, trigger)(editorView.state, editorView.dispatch);
88
- }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions]);
88
+ var rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
89
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
90
+ if (rowIndex !== undefined) {
91
+ var _api$analytics;
92
+ toggleActiveTableMenuWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)('row', rowIndex, trigger)(editorView.state, editorView.dispatch);
93
+ }
94
+ return;
95
+ }
96
+ toggleDragMenuWithAnalytics(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(undefined, 'row', rowIndex, trigger)(editorView.state, editorView.dispatch);
97
+ }, [editorView, hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions]);
89
98
  var rowIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.rowIndex;
90
99
  var handleMouseOut = useCallback(function () {
91
100
  if (tableActive) {