@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
@@ -2,4 +2,4 @@ import { getCellMenuComponents } from '../cell/getCellMenuComponents';
2
2
  import { getColumnMenuComponents } from '../column/getColumnMenuComponents';
3
3
  import { getRowMenuComponents } from '../row/getRowMenuComponents';
4
4
  import { getSharedItems } from './getSharedItems';
5
- export const getTableMenuComponents = params => [...getRowMenuComponents(params), ...getColumnMenuComponents(params), ...getCellMenuComponents(), ...getSharedItems(params)];
5
+ export const getTableMenuComponents = params => [...getRowMenuComponents(params), ...getColumnMenuComponents(params), ...getCellMenuComponents(params), ...getSharedItems(params)];
@@ -3,26 +3,55 @@ import "./BackgroundColorItem.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useCallback, useMemo } from 'react';
5
5
  import { useIntl } from 'react-intl';
6
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
7
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
7
8
  import { backgroundPaletteTooltipMessages, cellBackgroundColorPalette, ColorPalette } from '@atlaskit/editor-common/ui-color';
8
9
  import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
9
10
  import { NestedDropdownRightIcon, PaintBucketIcon, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
10
11
  import { Box } from '@atlaskit/primitives/compiled';
12
+ import { closeActiveTableMenu } from '../../../../pm-plugins/commands';
13
+ import { setColorWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
14
+ import { getPluginState } from '../../../../pm-plugins/plugin-factory';
15
+ import { useTableMenuContext } from '../TableMenuContext';
11
16
  const colorPaletteColumns = 7;
12
17
  const colorPaletteStyles = {
13
18
  container: "_1rjcu2gc",
14
19
  elemAfter: "_zulp1b66 _1e0c1txw _4cvr1h6o",
15
20
  colorPreview: "_2rko12b0 _1h6d1l7x _1dqonqa1 _189ee4h9 _1bsbdlk8 _4t3idlk8 _1o9zidpf"
16
21
  };
17
- export const BackgroundColorItem = () => {
22
+ export const BackgroundColorItem = ({
23
+ api
24
+ }) => {
25
+ var _useTableMenuContext, _api$analytics2;
26
+ const {
27
+ editorView
28
+ } = (_useTableMenuContext = useTableMenuContext()) !== null && _useTableMenuContext !== void 0 ? _useTableMenuContext : {};
18
29
  const {
19
30
  formatMessage
20
31
  } = useIntl();
21
- const onClick = useCallback(() => {}, []);
32
+ const selectedColor = useMemo(() => {
33
+ var _node$attrs;
34
+ if (!editorView) {
35
+ return '#ffffff';
36
+ }
37
+ const {
38
+ targetCellPosition
39
+ } = getPluginState(editorView.state);
40
+ const node = targetCellPosition ? editorView.state.doc.nodeAt(targetCellPosition) : null;
41
+ return hexToEditorBackgroundPaletteColor((node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.background) || '#ffffff');
42
+ }, [editorView]);
43
+ const onClick = useCallback(color => {
44
+ var _api$analytics;
45
+ if (!editorView) {
46
+ return;
47
+ }
48
+ setColorWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, color, editorView)(editorView.state, editorView.dispatch);
49
+ closeActiveTableMenu()(editorView.state, editorView.dispatch);
50
+ }, [api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, editorView]);
22
51
  // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
23
52
  const colorPreviewStyle = useMemo(() => ({
24
- backgroundColor: '#ffffff'
25
- }), []);
53
+ backgroundColor: selectedColor
54
+ }), [selectedColor]);
26
55
  const paletteOptions = useMemo(() => {
27
56
  return {
28
57
  palette: cellBackgroundColorPalette,
@@ -3,8 +3,8 @@ import { useIntl } from 'react-intl';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { backspace, tooltip } from '@atlaskit/editor-common/keymaps';
5
5
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
- import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
7
6
  import { CrossIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
7
+ import { closeActiveTableMenu } from '../../../../pm-plugins/commands';
8
8
  import { emptyMultipleCellsWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
9
9
  import { getPluginState } from '../../../../pm-plugins/plugin-factory';
10
10
  import { useTableMenuContext } from '../TableMenuContext';
@@ -12,10 +12,10 @@ export const ClearCellsItem = ({
12
12
  api
13
13
  }) => {
14
14
  var _tableMenuContext$sel, _tableMenuContext$sel2, _tooltip;
15
+ const tableMenuContext = useTableMenuContext();
15
16
  const {
16
17
  editorView
17
- } = useEditorToolbar();
18
- const tableMenuContext = useTableMenuContext();
18
+ } = tableMenuContext !== null && tableMenuContext !== void 0 ? tableMenuContext : {};
19
19
  const {
20
20
  formatMessage
21
21
  } = useIntl();
@@ -29,6 +29,7 @@ export const ClearCellsItem = ({
29
29
  targetCellPosition
30
30
  } = getPluginState(editorView.state);
31
31
  emptyMultipleCellsWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, targetCellPosition)(editorView.state, editorView.dispatch);
32
+ closeActiveTableMenu()(editorView.state, editorView.dispatch);
32
33
  };
33
34
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
34
35
  onClick: handleClick,
@@ -44,7 +44,8 @@ import { normaliseAlignment } from '../pm-plugins/utils/alignment';
44
44
  import { isTableNested } from '../pm-plugins/utils/nodes';
45
45
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../pm-plugins/utils/selection';
46
46
  import { getMergedCellsPositions } from '../pm-plugins/utils/table';
47
- import { applyMeasuredWidthToSelectedTable, isContentModeSupported } from '../pm-plugins/utils/tableMode';
47
+ import { applyMeasuredWidthToSelectedTable } from '../pm-plugins/utils/tableMode/apply-measured-width-to-selected-table';
48
+ import { isContentModeSupported } from '../pm-plugins/utils/tableMode/is-content-mode-supported';
48
49
  import { TableCssClassName } from '../types';
49
50
  import { FloatingAlignmentButtons } from './FloatingAlignmentButtons/FloatingAlignmentButtons';
50
51
  export const getToolbarMenuConfig = (config, state, {
@@ -41,7 +41,7 @@ import { getResizeState, updateColgroup } from '../pm-plugins/table-resizing/uti
41
41
  import { scaleTable } from '../pm-plugins/table-resizing/utils/scale-table';
42
42
  import { containsHeaderRow, isTableNested, isTableNestedInMoreThanOneNode, isTableNestedUnderBodiedSyncBlock, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, tablesHaveDifferentNoOfRows } from '../pm-plugins/utils/nodes';
43
43
  import { getAssistiveMessage } from '../pm-plugins/utils/table';
44
- import { isContentModeSupported } from '../pm-plugins/utils/tableMode';
44
+ import { isContentModeSupported } from '../pm-plugins/utils/tableMode/is-content-mode-supported';
45
45
  import { TableCssClassName as ClassName } from '../types';
46
46
  import { handleMouseOut, handleMouseOver, isTableInFocus, withCellTracking } from '../ui/event-handlers';
47
47
  import TableFloatingColumnControls from '../ui/TableFloatingColumnControls';
@@ -23,7 +23,7 @@ import { pluginConfig as getPluginConfig } from '../pm-plugins/create-plugin-con
23
23
  import { getPluginState } from '../pm-plugins/plugin-factory';
24
24
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
25
25
  import { isTableNested, tablesHaveDifferentColumnWidths } from '../pm-plugins/utils/nodes';
26
- import { isContentModeSupported } from '../pm-plugins/utils/tableMode';
26
+ import { isContentModeSupported } from '../pm-plugins/utils/tableMode/is-content-mode-supported';
27
27
  import { TableComponentWithSharedState } from './TableComponentWithSharedState';
28
28
  import { tableNodeSpecWithFixedToDOM } from './toDOM';
29
29
  var tableAttributes = function tableAttributes(node) {
@@ -12,7 +12,7 @@ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
12
  import { generateColgroupFromNode, getResizerMinWidth } from '../pm-plugins/table-resizing/utils/colgroup';
13
13
  import { TABLE_MAX_WIDTH, TABLE_FULL_WIDTH } from '../pm-plugins/table-resizing/utils/consts';
14
14
  import { getTableResizerContainerMaxWidthInCSS, getTableResizerContainerForFullPageWidthInCSS, getTableResizerItemWidthInCSS } from '../pm-plugins/table-resizing/utils/misc';
15
- import { isContentModeSupported } from '../pm-plugins/utils/tableMode';
15
+ import { isContentModeSupported } from '../pm-plugins/utils/tableMode/is-content-mode-supported';
16
16
  import { getAlignmentStyle } from './table-container-styles';
17
17
  export var tableNodeSpecWithFixedToDOM = function tableNodeSpecWithFixedToDOM(config) {
18
18
  var tableNode = config.isNestingSupported ? tableWithNestedTable : table;
@@ -0,0 +1,45 @@
1
+ import { createCommand, getPluginState } from '../plugin-factory';
2
+ export var closeActiveTableMenu = function closeActiveTableMenu() {
3
+ return createCommand(function (state) {
4
+ var _getPluginState = getPluginState(state),
5
+ activeTableMenu = _getPluginState.activeTableMenu;
6
+ if (!activeTableMenu || activeTableMenu.type === 'none') {
7
+ return false;
8
+ }
9
+ return {
10
+ type: 'SET_ACTIVE_TABLE_MENU',
11
+ data: {
12
+ activeTableMenu: {
13
+ type: 'none'
14
+ }
15
+ }
16
+ };
17
+ }, function (tr) {
18
+ return tr.setMeta('addToHistory', false);
19
+ });
20
+ };
21
+ var isSameActiveTableMenu = function isSameActiveTableMenu(current, next) {
22
+ if (!current || current.type !== next.type) {
23
+ return false;
24
+ }
25
+ if (current.type === 'row' || current.type === 'column') {
26
+ return next.type === current.type && current.index === next.index;
27
+ }
28
+ return true;
29
+ };
30
+ export var toggleActiveTableMenu = function toggleActiveTableMenu(activeTableMenu) {
31
+ return createCommand(function (state) {
32
+ var _getPluginState2 = getPluginState(state),
33
+ currentActiveTableMenu = _getPluginState2.activeTableMenu;
34
+ return {
35
+ type: 'SET_ACTIVE_TABLE_MENU',
36
+ data: {
37
+ activeTableMenu: isSameActiveTableMenu(currentActiveTableMenu, activeTableMenu) ? {
38
+ type: 'none'
39
+ } : activeTableMenu
40
+ }
41
+ };
42
+ }, function (tr) {
43
+ return tr.setMeta('addToHistory', false);
44
+ });
45
+ };
@@ -13,6 +13,7 @@ import { deleteRows } from '../transforms/delete-rows';
13
13
  import { mergeCells } from '../transforms/merge';
14
14
  import { withEditorAnalyticsAPI, getSelectedCellInfo, getSelectedTableInfo } from '../utils/analytics';
15
15
  import { checkIfNumberColumnEnabled } from '../utils/nodes';
16
+ import { toggleActiveTableMenu } from './active-table-menu';
16
17
  import { clearMultipleCells } from './clear';
17
18
  import { wrapTableInExpand } from './collapse';
18
19
  import { changeColumnWidthByStep } from './column-resize';
@@ -23,8 +24,38 @@ import { deleteTable, deleteTableIfSelected, getTableSelectionType, setMultipleC
23
24
  import { sortByColumn } from './sort';
24
25
  import { splitCell } from './split-cell';
25
26
  import { toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn } from './toggle';
26
-
27
- // #region Analytics wrappers
27
+ export var toggleActiveTableMenuWithAnalytics = function toggleActiveTableMenuWithAnalytics(editorAnalyticsAPI) {
28
+ return function (direction, index) {
29
+ var trigger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'mouse';
30
+ return withEditorAnalyticsAPI(function (state) {
31
+ var _getPluginState = getPluginState(state),
32
+ previousActiveTableMenu = _getPluginState.activeTableMenu;
33
+ var isSameActiveMenu = (previousActiveTableMenu === null || previousActiveTableMenu === void 0 ? void 0 : previousActiveTableMenu.type) === direction && previousActiveTableMenu.index === index;
34
+ if (isSameActiveMenu) {
35
+ return undefined;
36
+ }
37
+ return {
38
+ action: TABLE_ACTION.DRAG_MENU_OPENED,
39
+ actionSubject: ACTION_SUBJECT.TABLE,
40
+ actionSubjectId: null,
41
+ eventType: EVENT_TYPE.TRACK,
42
+ attributes: {
43
+ inputMethod: trigger === 'keyboard' ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE,
44
+ direction: direction
45
+ }
46
+ };
47
+ })(editorAnalyticsAPI)(function (state, dispatch) {
48
+ if (dispatch) {
49
+ toggleActiveTableMenu({
50
+ type: direction,
51
+ index: index,
52
+ openedBy: trigger
53
+ })(state, dispatch);
54
+ }
55
+ return true;
56
+ });
57
+ };
58
+ };
28
59
  export var emptyMultipleCellsWithAnalytics = function emptyMultipleCellsWithAnalytics(editorAnalyticsAPI) {
29
60
  return function (inputMethod, targetCellPosition) {
30
61
  return withEditorAnalyticsAPI(function (_ref) {
@@ -189,8 +220,8 @@ export var changeColumnWidthByStepWithAnalytics = function changeColumnWidthBySt
189
220
  table = _getSelectedTableInfo2.table,
190
221
  totalRowCount = _getSelectedTableInfo2.totalRowCount,
191
222
  totalColumnCount = _getSelectedTableInfo2.totalColumnCount;
192
- var _getPluginState = getPluginState(state),
193
- colIndex = _getPluginState.hoveredCell.colIndex;
223
+ var _getPluginState2 = getPluginState(state),
224
+ colIndex = _getPluginState2.hoveredCell.colIndex;
194
225
  return {
195
226
  action: TABLE_ACTION.COLUMN_RESIZED,
196
227
  actionSubject: ACTION_SUBJECT.TABLE,
@@ -310,8 +341,8 @@ export var deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = function delete
310
341
  }
311
342
  var selectionType = getTableSelectionType(selection);
312
343
  if (selectionType === 'row') {
313
- var _getPluginState2 = getPluginState(state),
314
- pluginConfig = _getPluginState2.pluginConfig;
344
+ var _getPluginState3 = getPluginState(state),
345
+ pluginConfig = _getPluginState3.pluginConfig;
315
346
  var isHeaderRowRequired = pluginConfig.isHeaderRowRequired || false;
316
347
  return deleteRowsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, rect, isHeaderRowRequired)(state, dispatch);
317
348
  } else if (selectionType === 'column') {
@@ -355,8 +386,8 @@ export var toggleHeaderRowWithAnalytics = function toggleHeaderRowWithAnalytics(
355
386
  var _getSelectedTableInfo7 = getSelectedTableInfo(state.selection),
356
387
  totalRowCount = _getSelectedTableInfo7.totalRowCount,
357
388
  totalColumnCount = _getSelectedTableInfo7.totalColumnCount;
358
- var _getPluginState3 = getPluginState(state),
359
- isHeaderRowEnabled = _getPluginState3.isHeaderRowEnabled;
389
+ var _getPluginState4 = getPluginState(state),
390
+ isHeaderRowEnabled = _getPluginState4.isHeaderRowEnabled;
360
391
  return {
361
392
  action: TABLE_ACTION.TOGGLED_HEADER_ROW,
362
393
  actionSubject: ACTION_SUBJECT.TABLE,
@@ -375,8 +406,8 @@ export var toggleHeaderColumnWithAnalytics = function toggleHeaderColumnWithAnal
375
406
  var _getSelectedTableInfo8 = getSelectedTableInfo(state.selection),
376
407
  totalRowCount = _getSelectedTableInfo8.totalRowCount,
377
408
  totalColumnCount = _getSelectedTableInfo8.totalColumnCount;
378
- var _getPluginState4 = getPluginState(state),
379
- isHeaderColumnEnabled = _getPluginState4.isHeaderColumnEnabled;
409
+ var _getPluginState5 = getPluginState(state),
410
+ isHeaderColumnEnabled = _getPluginState5.isHeaderColumnEnabled;
380
411
  return {
381
412
  action: TABLE_ACTION.TOGGLED_HEADER_COLUMN,
382
413
  actionSubject: ACTION_SUBJECT.TABLE,
@@ -4,6 +4,7 @@
4
4
  export { hoverColumns, hoverRows, hoverTable, hoverCell, hoverMergedCells, clearHoverSelection, showResizeHandleLine, hideResizeHandleLine, setTableHovered } from './hover';
5
5
  export { insertColumn, insertRow, createTable } from './insert';
6
6
  export { getNextLayout, toggleContextualMenu, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './toggle';
7
+ export { closeActiveTableMenu, toggleActiveTableMenu } from './active-table-menu';
7
8
  export { clearMultipleCells } from './clear';
8
9
  export { autoSizeTable, convertFirstRowToHeader, deleteTable, hideInsertColumnOrRowButton, moveCursorBackward, selectColumn, selectColumns, selectRow, selectRows, setCellAttr, setEditorFocus, setMultipleCellAttrs, setTableRef, showInsertColumnButton, showInsertRowButton, transformSliceToAddTableHeaders, triggerUnlessTableHeader, addBoldInEmptyHeaderCells, addResizeHandleDecorations, updateWidthToWidest, setFocusToCellMenu } from './misc';
9
10
  export { sortByColumn } from './sort';
@@ -146,6 +146,8 @@ export var cloneSourceWithAnalytics = function cloneSourceWithAnalytics(editorAn
146
146
  });
147
147
  };
148
148
  };
149
+
150
+ // remove when 'platform_editor_table_menu_updates' is cleaned up
149
151
  export var toggleDragMenuWithAnalytics = function toggleDragMenuWithAnalytics(editorAnalyticsAPI) {
150
152
  return function (isDragMenuOpen, direction, index) {
151
153
  var trigger = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'mouse';
@@ -8,6 +8,7 @@ import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-sc
8
8
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
9
9
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
10
10
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
+ import { closeActiveTableMenu } from '../commands/active-table-menu';
11
12
  import { getPluginState as getTablePluginState } from '../plugin-factory';
12
13
  import { pluginKey as tablePluginKey } from '../plugin-key';
13
14
  import { insertColgroupFromNode } from '../table-resizing/utils/colgroup';
@@ -87,6 +88,9 @@ var destroyFn = function destroyFn(editorView, editorAnalyticsAPI, isTableScalin
87
88
  (_insm$session3 = insm.session) === null || _insm$session3 === void 0 || _insm$session3.startFeature('tableDragAndDrop');
88
89
  }
89
90
  toggleDragMenu(false)(editorView.state, editorView.dispatch);
91
+ if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
92
+ closeActiveTableMenu()(editorView.state, editorView.dispatch);
93
+ }
90
94
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.commands.setCurrentUserIntent('dragging'));
91
95
  },
92
96
  onDrag: function onDrag(event) {
@@ -9,6 +9,7 @@ import { isTextInput } from '@atlaskit/editor-common/utils';
9
9
 
10
10
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
11
11
  import { findTable } from '@atlaskit/editor-tables/utils';
12
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
13
  import { defaultTableSelection } from './default-table-selection';
13
14
  import { pluginKey as tableResizingPluginKey } from './table-resizing/plugin-key';
14
15
  import { isTableCollapsible } from './utils/collapse';
@@ -43,8 +44,14 @@ var updateTargetCellPosition = function updateTargetCellPosition(_ref) {
43
44
  if (pluginState.targetCellPosition === targetCellPosition) {
44
45
  return pluginState;
45
46
  }
47
+
48
+ // The updated table menu is anchored to the current target cell. When selection moves
49
+ // to another cell, close the active menu so render state cannot point at a stale anchor.
46
50
  return _objectSpread(_objectSpread({}, pluginState), {}, {
47
- targetCellPosition: targetCellPosition
51
+ targetCellPosition: targetCellPosition,
52
+ activeTableMenu: pluginState.activeTableMenu != null && pluginState.activeTableMenu.type !== 'none' && expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? {
53
+ type: 'none'
54
+ } : pluginState.activeTableMenu
48
55
  });
49
56
  };
50
57
  };
@@ -28,7 +28,8 @@ import { fixTables } from './transforms/fix-tables';
28
28
  import { replaceSelectedTable } from './transforms/replace-table';
29
29
  import { findControlsHoverDecoration } from './utils/decoration';
30
30
  import { transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell, transformSliceToRemoveOpenTable, transformSliceToRemoveNestedTables, isHeaderRowRequired, transformSliceTableLayoutDefaultToCenter } from './utils/paste';
31
- import { applyMeasuredWidthToAllTables, isContentModeSupported } from './utils/tableMode';
31
+ import { applyMeasuredWidthToAllTables } from './utils/tableMode/apply-measured-width-to-all-tables';
32
+ import { isContentModeSupported } from './utils/tableMode/is-content-mode-supported';
32
33
  export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, nodeViewPortalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, fullWidthModeEnabled, previousFullWidthModeEnabled, editorAnalyticsAPI, pluginInjectionApi, isTableScalingEnabled, shouldUseIncreasedScalingPercent, isCommentEditor, isChromelessEditor, allowFixedColumnWidthOption) {
33
34
  var _accessibilityUtils;
34
35
  var state = createPluginState(dispatch, _objectSpread(_objectSpread(_objectSpread({
@@ -26,6 +26,8 @@ export default (function (pluginState, action) {
26
26
  return _objectSpread(_objectSpread({}, pluginState), {}, {
27
27
  isContextualMenuOpen: !pluginState.isContextualMenuOpen
28
28
  });
29
+ case 'SET_ACTIVE_TABLE_MENU':
30
+ return _objectSpread(_objectSpread({}, pluginState), action.data);
29
31
  case 'SHOW_INSERT_ROW_BUTTON':
30
32
  if (action.data.insertRowButtonIndex === pluginState.insertRowButtonIndex) {
31
33
  return pluginState;
@@ -18,7 +18,7 @@ import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorMaxWi
18
18
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
19
19
  import { TABLE_MAX_WIDTH, TABLE_FULL_WIDTH } from './table-resizing/utils/consts';
20
20
  import { ALIGN_START } from './utils/alignment';
21
- import { isContentModeSupported } from './utils/tableMode';
21
+ import { isContentModeSupported } from './utils/tableMode/is-content-mode-supported';
22
22
  export var pluginKey = new PluginKey('tableWidthPlugin');
23
23
  var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, maxWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled, isCommentEditor) {
24
24
  return new SafePlugin({
@@ -5,10 +5,11 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
5
  import { akEditorFullWidthLayoutWidth, akEditorMaxLayoutWidth } from '@atlaskit/editor-shared-styles';
6
6
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
7
7
  import { updateCellsMarkup } from './table-transform-utils';
8
- var tableWidth = function tableWidth(contentWidth) {
8
+ export var clampToEditorMaxWidth = function clampToEditorMaxWidth(contentWidth) {
9
9
  var maxEditorWidth = expValEquals('editor_tinymce_full_width_mode', 'isEnabled', true) || expValEquals('confluence_max_width_content_appearance', 'isEnabled', true) ? akEditorMaxLayoutWidth : akEditorFullWidthLayoutWidth;
10
10
  return Math.min(maxEditorWidth, contentWidth);
11
11
  };
12
+ var tableWidth = clampToEditorMaxWidth;
12
13
  export var getTableMeasurement = function getTableMeasurement(tableRef) {
13
14
  var colWidths = getRenderedColgroupColumnWidths(tableRef);
14
15
  var totalContentWidth = colWidths.reduce(function (acc, current) {
@@ -0,0 +1,65 @@
1
+ import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
2
+ import { TableSharedCssClassName } from '@atlaskit/editor-common/styles';
3
+ import { hasTableBeenResized } from '@atlaskit/editor-common/table';
4
+ import { applyTableMeasurement, getTableMeasurement } from '../../transforms/content-mode';
5
+
6
+ /**
7
+ * Iterates all top-level tables in the document, and for those in content mode,
8
+ * measures rendered column widths and sets colwidth + table width attributes
9
+ * in a single batched transaction.
10
+ */
11
+ export var applyMeasuredWidthToAllTables = function applyMeasuredWidthToAllTables(view, pluginInjectionApi) {
12
+ var _view$state = view.state,
13
+ doc = _view$state.doc,
14
+ schema = _view$state.schema;
15
+ var tr = view.state.tr;
16
+ var table = schema.nodes.table;
17
+ var modified = false;
18
+ var measuredTables = [];
19
+
20
+ // modify only top-level tables
21
+ doc.forEach(function (node, offset) {
22
+ if (node.type !== table || hasTableBeenResized(node) && node.attrs.layout !== 'align-start') {
23
+ return;
24
+ }
25
+ var domNode = view.domAtPos(offset + 1).node;
26
+ var tableWrapper = domNode instanceof HTMLElement ? domNode.closest(".".concat(TableSharedCssClassName.TABLE_VIEW_CONTENT_WRAP)) : null;
27
+ var tableRef = tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.querySelector('table');
28
+ if (!tableRef) {
29
+ return;
30
+ }
31
+ measuredTables.push({
32
+ node: node,
33
+ offset: offset,
34
+ measurement: getTableMeasurement(tableRef)
35
+ });
36
+ });
37
+ measuredTables.forEach(function (_ref) {
38
+ var node = _ref.node,
39
+ offset = _ref.offset,
40
+ measurement = _ref.measurement;
41
+ tr = applyTableMeasurement(tr, node, measurement, offset);
42
+ modified = true;
43
+ });
44
+ if (modified) {
45
+ var _pluginInjectionApi$a, _pluginInjectionApi$w, _pluginInjectionApi$w2;
46
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || _pluginInjectionApi$a.attachAnalyticsEvent({
47
+ action: TABLE_ACTION.FIT_TO_CONTENT_AUTO_CONVERTED,
48
+ actionSubject: ACTION_SUBJECT.TABLE,
49
+ actionSubjectId: null,
50
+ eventType: EVENT_TYPE.TRACK,
51
+ attributes: {
52
+ editorContainerWidth: (_pluginInjectionApi$w = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$w2 = pluginInjectionApi.width) === null || _pluginInjectionApi$w2 === void 0 || (_pluginInjectionApi$w2 = _pluginInjectionApi$w2.sharedState.currentState()) === null || _pluginInjectionApi$w2 === void 0 ? void 0 : _pluginInjectionApi$w2.width) !== null && _pluginInjectionApi$w !== void 0 ? _pluginInjectionApi$w : 0,
53
+ totalTablesResized: measuredTables.length,
54
+ measurements: measuredTables.map(function (_ref2) {
55
+ var measurement = _ref2.measurement;
56
+ return {
57
+ tableWidth: measurement.tableWidth,
58
+ totalColumnCount: measurement.colWidths.length
59
+ };
60
+ })
61
+ }
62
+ })(tr);
63
+ view.dispatch(tr.setMeta('addToHistory', false));
64
+ }
65
+ };
@@ -0,0 +1,36 @@
1
+ import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
2
+ import { findTable } from '@atlaskit/editor-tables/utils';
3
+ import { applyTableMeasurement } from '../../transforms/content-mode';
4
+ import { measureTableWithAutoLayout } from './measure-table-with-auto-layout';
5
+
6
+ /**
7
+ * Used to measure a selected table width with it's content being laid out natively by the browser
8
+ */
9
+ export var applyMeasuredWidthToSelectedTable = function applyMeasuredWidthToSelectedTable(view, api) {
10
+ var _api$width, _api$analytics, _api$width$sharedStat, _api$width2;
11
+ var tableObject = findTable(view.state.selection);
12
+ if (!tableObject) {
13
+ return;
14
+ }
15
+ var node = tableObject.node,
16
+ pos = tableObject.pos;
17
+ var tableState = api === null || api === void 0 ? void 0 : api.table.sharedState.currentState();
18
+ if (!(tableState !== null && tableState !== void 0 && tableState.tableRef)) {
19
+ return;
20
+ }
21
+ var editorContainerWidth = api === null || api === void 0 || (_api$width = api.width) === null || _api$width === void 0 || (_api$width = _api$width.sharedState.currentState()) === null || _api$width === void 0 ? void 0 : _api$width.width;
22
+ var measurement = measureTableWithAutoLayout(tableState.tableRef, editorContainerWidth);
23
+ var tr = applyTableMeasurement(view.state.tr, node, measurement, pos);
24
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
25
+ action: TABLE_ACTION.FIT_TO_CONTENT_ON_DEMAND,
26
+ actionSubject: ACTION_SUBJECT.TABLE,
27
+ actionSubjectId: null,
28
+ eventType: EVENT_TYPE.TRACK,
29
+ attributes: {
30
+ editorContainerWidth: (_api$width$sharedStat = api === null || api === void 0 || (_api$width2 = api.width) === null || _api$width2 === void 0 || (_api$width2 = _api$width2.sharedState.currentState()) === null || _api$width2 === void 0 ? void 0 : _api$width2.width) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : 0,
31
+ tableWidth: measurement.tableWidth,
32
+ totalColumnCount: measurement.colWidths.length
33
+ }
34
+ })(tr);
35
+ view.dispatch(tr);
36
+ };
@@ -0,0 +1,6 @@
1
+ export var isContentModeSupported = function isContentModeSupported(_ref) {
2
+ var allowColumnResizing = _ref.allowColumnResizing,
3
+ allowTableResizing = _ref.allowTableResizing,
4
+ isFullPageEditor = _ref.isFullPageEditor;
5
+ return allowColumnResizing && allowTableResizing && isFullPageEditor;
6
+ };
@@ -0,0 +1,107 @@
1
+ import { TableSharedCssClassName } from '@atlaskit/editor-common/styles';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { getTableMeasurement } from '../../transforms/content-mode';
4
+ import { restoreResizerContainer, runSmartAdjust } from './smart-adjust/run-smart-adjust';
5
+ export var measureTableWithAutoLayout = function measureTableWithAutoLayout(tableRef, editorContainerWidth) {
6
+ var cols = Array.from(tableRef.querySelectorAll(':scope > colgroup > col'));
7
+ var contentWrap = tableRef.closest(".".concat(TableSharedCssClassName.TABLE_VIEW_CONTENT_WRAP));
8
+ var resizerContainer = contentWrap === null || contentWrap === void 0 ? void 0 : contentWrap.querySelector(".".concat(TableSharedCssClassName.TABLE_RESIZER_CONTAINER));
9
+ var resizerItem = resizerContainer === null || resizerContainer === void 0 ? void 0 : resizerContainer.querySelector('.resizer-item.display-handle');
10
+ var prevTableWidth = tableRef.style.width;
11
+ var prevTableLayout = tableRef.style.tableLayout;
12
+ var prevColWidths = cols.map(function (col) {
13
+ return col.style.width;
14
+ });
15
+ var prevResizerItemWidth = resizerItem === null || resizerItem === void 0 ? void 0 : resizerItem.style.width;
16
+ tableRef.style.width = '';
17
+ tableRef.style.tableLayout = 'auto';
18
+ cols.forEach(function (col) {
19
+ return col.style.width = '';
20
+ });
21
+ if (fg('platform_editor_table_fit_to_content_smart_adjust')) {
22
+ var hadTableSticky = tableRef.classList.contains(TableSharedCssClassName.TABLE_STICKY);
23
+ var prevTableMarginTop = tableRef.style.marginTop;
24
+ if (hadTableSticky) {
25
+ tableRef.classList.remove(TableSharedCssClassName.TABLE_NATIVE_STICKY);
26
+ }
27
+ if (prevTableMarginTop) {
28
+ tableRef.style.marginTop = '';
29
+ }
30
+ var stickyRows = Array.from(tableRef.querySelectorAll("tr.sticky, tr.".concat(TableSharedCssClassName.TABLE_NATIVE_STICKY)));
31
+ var prevStickyRowState = stickyRows.map(function (row) {
32
+ return {
33
+ row: row,
34
+ hadSticky: row.classList.contains('sticky'),
35
+ hadNative: row.classList.contains(TableSharedCssClassName.TABLE_NATIVE_STICKY),
36
+ width: row.style.width,
37
+ top: row.style.top,
38
+ position: row.style.position,
39
+ gridTemplateColumns: row.style.gridTemplateColumns
40
+ };
41
+ });
42
+ stickyRows.forEach(function (row) {
43
+ row.classList.remove('sticky');
44
+ row.classList.remove(TableSharedCssClassName.TABLE_NATIVE_STICKY);
45
+ row.style.width = '';
46
+ row.style.top = '';
47
+ row.style.position = '';
48
+ row.style.gridTemplateColumns = '';
49
+ });
50
+ try {
51
+ return runSmartAdjust(tableRef, resizerContainer, resizerItem, editorContainerWidth);
52
+ } finally {
53
+ tableRef.style.width = prevTableWidth;
54
+ tableRef.style.tableLayout = prevTableLayout;
55
+ cols.forEach(function (col, i) {
56
+ return col.style.width = prevColWidths[i];
57
+ });
58
+ if (hadTableSticky) {
59
+ tableRef.classList.add(TableSharedCssClassName.TABLE_STICKY);
60
+ }
61
+ if (prevTableMarginTop) {
62
+ tableRef.style.marginTop = prevTableMarginTop;
63
+ }
64
+ prevStickyRowState.forEach(function (state) {
65
+ if (state.hadSticky) {
66
+ state.row.classList.add('sticky');
67
+ }
68
+ if (state.hadNative) {
69
+ state.row.classList.add(TableSharedCssClassName.TABLE_NATIVE_STICKY);
70
+ }
71
+ if (state.width) {
72
+ state.row.style.width = state.width;
73
+ }
74
+ if (state.top) {
75
+ state.row.style.top = state.top;
76
+ }
77
+ if (state.position) {
78
+ state.row.style.position = state.position;
79
+ }
80
+ if (state.gridTemplateColumns) {
81
+ state.row.style.gridTemplateColumns = state.gridTemplateColumns;
82
+ }
83
+ });
84
+ restoreResizerContainer(resizerContainer);
85
+ if (resizerItem) {
86
+ resizerItem.style.width = prevResizerItemWidth !== null && prevResizerItemWidth !== void 0 ? prevResizerItemWidth : '';
87
+ }
88
+ }
89
+ }
90
+ if (resizerContainer) {
91
+ resizerContainer.style.width = 'var(--ak-editor-table-width)';
92
+ resizerContainer.style.setProperty('--ak-editor-table-width', 'max-content');
93
+ }
94
+ if (resizerItem) {
95
+ resizerItem.style.width = 'max-content';
96
+ }
97
+ var measurement = getTableMeasurement(tableRef);
98
+ tableRef.style.width = prevTableWidth;
99
+ tableRef.style.tableLayout = prevTableLayout;
100
+ cols.forEach(function (col, i) {
101
+ return col.style.width = prevColWidths[i];
102
+ });
103
+ if (resizerItem) {
104
+ resizerItem.style.width = prevResizerItemWidth !== null && prevResizerItemWidth !== void 0 ? prevResizerItemWidth : '';
105
+ }
106
+ return measurement;
107
+ };
@@ -0,0 +1,4 @@
1
+ /** Each column's max width is `MAX × (usableWidth / numCols)`. */
2
+ export var EVEN_SHARE_RATIO = {
3
+ MAX: 2
4
+ };