@atlaskit/editor-plugin-table 19.0.1 → 21.0.0

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 (131) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +2 -2
  3. package/dist/cjs/nodeviews/TableResizer.js +2 -2
  4. package/dist/cjs/nodeviews/table.js +18 -2
  5. package/dist/cjs/nodeviews/toDOM.js +18 -4
  6. package/dist/cjs/pm-plugins/main.js +38 -4
  7. package/dist/cjs/pm-plugins/table-width.js +10 -0
  8. package/dist/cjs/pm-plugins/transforms/content-mode.js +48 -0
  9. package/dist/cjs/pm-plugins/transforms/fix-tables.js +4 -35
  10. package/dist/cjs/pm-plugins/transforms/table-transform-utils.js +62 -0
  11. package/dist/cjs/pm-plugins/utils/decoration.js +2 -2
  12. package/dist/cjs/pm-plugins/utils/tableMode.js +149 -0
  13. package/dist/cjs/pm-plugins/view-mode-sort/index.js +2 -2
  14. package/dist/cjs/ui/ColumnResizeWidget/index.js +2 -2
  15. package/dist/cjs/ui/DragHandle/index.js +2 -2
  16. package/dist/cjs/ui/FloatingContextualButton/index.js +2 -2
  17. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +2 -2
  18. package/dist/cjs/ui/FloatingDeleteButton/DeleteButton.js +2 -2
  19. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +2 -2
  20. package/dist/cjs/ui/FloatingInsertButton/InsertButton.js +3 -3
  21. package/dist/cjs/ui/FloatingInsertButton/index.js +2 -2
  22. package/dist/cjs/ui/TableFloatingControls/CornerControls/ClassicCornerControls.js +2 -2
  23. package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +3 -3
  24. package/dist/cjs/ui/TableFloatingControls/RowControls/ClassicControls.js +2 -2
  25. package/dist/cjs/ui/TableFullWidthLabel/index.js +2 -2
  26. package/dist/cjs/ui/event-handlers.js +3 -2
  27. package/dist/cjs/ui/toolbar.js +25 -2
  28. package/dist/es2019/nodeviews/TableComponent.js +1 -1
  29. package/dist/es2019/nodeviews/TableResizer.js +1 -1
  30. package/dist/es2019/nodeviews/table.js +18 -2
  31. package/dist/es2019/nodeviews/toDOM.js +18 -4
  32. package/dist/es2019/pm-plugins/main.js +38 -4
  33. package/dist/es2019/pm-plugins/table-width.js +10 -0
  34. package/dist/es2019/pm-plugins/transforms/content-mode.js +39 -0
  35. package/dist/es2019/pm-plugins/transforms/fix-tables.js +2 -33
  36. package/dist/es2019/pm-plugins/transforms/table-transform-utils.js +56 -0
  37. package/dist/es2019/pm-plugins/utils/decoration.js +1 -1
  38. package/dist/es2019/pm-plugins/utils/tableMode.js +148 -0
  39. package/dist/es2019/pm-plugins/view-mode-sort/index.js +1 -1
  40. package/dist/es2019/ui/ColumnResizeWidget/index.js +1 -1
  41. package/dist/es2019/ui/DragHandle/index.js +1 -1
  42. package/dist/es2019/ui/FloatingContextualButton/index.js +1 -1
  43. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  44. package/dist/es2019/ui/FloatingDeleteButton/DeleteButton.js +1 -1
  45. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +1 -1
  46. package/dist/es2019/ui/FloatingInsertButton/InsertButton.js +1 -1
  47. package/dist/es2019/ui/FloatingInsertButton/index.js +1 -1
  48. package/dist/es2019/ui/TableFloatingControls/CornerControls/ClassicCornerControls.js +1 -1
  49. package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +1 -1
  50. package/dist/es2019/ui/TableFloatingControls/RowControls/ClassicControls.js +1 -1
  51. package/dist/es2019/ui/TableFullWidthLabel/index.js +1 -1
  52. package/dist/es2019/ui/event-handlers.js +4 -3
  53. package/dist/es2019/ui/toolbar.js +23 -2
  54. package/dist/esm/nodeviews/TableComponent.js +1 -1
  55. package/dist/esm/nodeviews/TableResizer.js +1 -1
  56. package/dist/esm/nodeviews/table.js +18 -2
  57. package/dist/esm/nodeviews/toDOM.js +18 -4
  58. package/dist/esm/pm-plugins/main.js +38 -4
  59. package/dist/esm/pm-plugins/table-width.js +10 -0
  60. package/dist/esm/pm-plugins/transforms/content-mode.js +41 -0
  61. package/dist/esm/pm-plugins/transforms/fix-tables.js +2 -33
  62. package/dist/esm/pm-plugins/transforms/table-transform-utils.js +56 -0
  63. package/dist/esm/pm-plugins/utils/decoration.js +1 -1
  64. package/dist/esm/pm-plugins/utils/tableMode.js +143 -0
  65. package/dist/esm/pm-plugins/view-mode-sort/index.js +1 -1
  66. package/dist/esm/ui/ColumnResizeWidget/index.js +1 -1
  67. package/dist/esm/ui/DragHandle/index.js +1 -1
  68. package/dist/esm/ui/FloatingContextualButton/index.js +1 -1
  69. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +1 -1
  70. package/dist/esm/ui/FloatingDeleteButton/DeleteButton.js +1 -1
  71. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +1 -1
  72. package/dist/esm/ui/FloatingInsertButton/InsertButton.js +1 -1
  73. package/dist/esm/ui/FloatingInsertButton/index.js +1 -1
  74. package/dist/esm/ui/TableFloatingControls/CornerControls/ClassicCornerControls.js +1 -1
  75. package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +1 -1
  76. package/dist/esm/ui/TableFloatingControls/RowControls/ClassicControls.js +1 -1
  77. package/dist/esm/ui/TableFullWidthLabel/index.js +1 -1
  78. package/dist/esm/ui/event-handlers.js +4 -3
  79. package/dist/esm/ui/toolbar.js +25 -2
  80. package/dist/types/nodeviews/TableComponent.d.ts +2 -2
  81. package/dist/types/pm-plugins/commands/column-resize.d.ts +1 -1
  82. package/dist/types/pm-plugins/commands/commands-with-analytics.d.ts +1 -1
  83. package/dist/types/pm-plugins/commands/go-to-next-cell.d.ts +1 -1
  84. package/dist/types/pm-plugins/commands/selection.d.ts +1 -1
  85. package/dist/types/pm-plugins/decorations/utils/column-resizing.d.ts +1 -1
  86. package/dist/types/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +1 -1
  87. package/dist/types/pm-plugins/keymap.d.ts +1 -1
  88. package/dist/types/pm-plugins/main.d.ts +1 -1
  89. package/dist/types/pm-plugins/table-selection-keymap.d.ts +1 -1
  90. package/dist/types/pm-plugins/transforms/content-mode.d.ts +8 -0
  91. package/dist/types/pm-plugins/transforms/table-transform-utils.d.ts +11 -0
  92. package/dist/types/pm-plugins/utils/decoration.d.ts +1 -1
  93. package/dist/types/pm-plugins/utils/table.d.ts +1 -1
  94. package/dist/types/pm-plugins/utils/tableMode.d.ts +22 -0
  95. package/dist/types/types/index.d.ts +4 -1
  96. package/dist/types/ui/DragHandle/index.d.ts +2 -2
  97. package/dist/types/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -2
  98. package/dist/types/ui/FloatingDeleteButton/DeleteButton.d.ts +2 -2
  99. package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
  100. package/dist/types/ui/FloatingInsertButton/InsertButton.d.ts +3 -3
  101. package/dist/types/ui/FloatingInsertButton/index.d.ts +2 -2
  102. package/dist/types/ui/TableFloatingControls/CornerControls/ClassicCornerControls.d.ts +2 -2
  103. package/dist/types/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +3 -3
  104. package/dist/types/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +2 -2
  105. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +2 -2
  106. package/dist/types-ts4.5/pm-plugins/commands/column-resize.d.ts +1 -1
  107. package/dist/types-ts4.5/pm-plugins/commands/commands-with-analytics.d.ts +1 -1
  108. package/dist/types-ts4.5/pm-plugins/commands/go-to-next-cell.d.ts +1 -1
  109. package/dist/types-ts4.5/pm-plugins/commands/selection.d.ts +1 -1
  110. package/dist/types-ts4.5/pm-plugins/decorations/utils/column-resizing.d.ts +1 -1
  111. package/dist/types-ts4.5/pm-plugins/drag-and-drop/commands-with-analytics.d.ts +1 -1
  112. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +1 -1
  113. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  114. package/dist/types-ts4.5/pm-plugins/table-selection-keymap.d.ts +1 -1
  115. package/dist/types-ts4.5/pm-plugins/transforms/content-mode.d.ts +8 -0
  116. package/dist/types-ts4.5/pm-plugins/transforms/table-transform-utils.d.ts +11 -0
  117. package/dist/types-ts4.5/pm-plugins/utils/decoration.d.ts +1 -1
  118. package/dist/types-ts4.5/pm-plugins/utils/table.d.ts +1 -1
  119. package/dist/types-ts4.5/pm-plugins/utils/tableMode.d.ts +22 -0
  120. package/dist/types-ts4.5/types/index.d.ts +4 -1
  121. package/dist/types-ts4.5/ui/DragHandle/index.d.ts +2 -2
  122. package/dist/types-ts4.5/ui/FloatingContextualMenu/ContextualMenu.d.ts +2 -2
  123. package/dist/types-ts4.5/ui/FloatingDeleteButton/DeleteButton.d.ts +2 -2
  124. package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
  125. package/dist/types-ts4.5/ui/FloatingInsertButton/InsertButton.d.ts +3 -3
  126. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +2 -2
  127. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/ClassicCornerControls.d.ts +2 -2
  128. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +3 -3
  129. package/dist/types-ts4.5/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +2 -2
  130. package/package.json +25 -21
  131. package/report.api.md +1 -1
@@ -1,3 +1,4 @@
1
+ import { bind } from 'bind-event-listener';
1
2
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
3
  import { getBrowserInfo } from '@atlaskit/editor-common/browser';
3
4
  import { insideTable } from '@atlaskit/editor-common/core-utils';
@@ -24,10 +25,13 @@ import { fixTables } from './transforms/fix-tables';
24
25
  import { replaceSelectedTable } from './transforms/replace-table';
25
26
  import { findControlsHoverDecoration } from './utils/decoration';
26
27
  import { transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell, transformSliceToRemoveOpenTable, transformSliceToRemoveNestedTables, isHeaderRowRequired, transformSliceTableLayoutDefaultToCenter } from './utils/paste';
28
+ import { applyMeasuredWidthToAllTables, isContentModeSupported } from './utils/tableMode';
27
29
  export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI, nodeViewPortalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, fullWidthModeEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi, isTableScalingEnabled, shouldUseIncreasedScalingPercent, isCommentEditor, isChromelessEditor, allowFixedColumnWidthOption) => {
28
30
  var _accessibilityUtils;
29
31
  const state = createPluginState(dispatch, {
30
32
  pluginConfig,
33
+ isCommentEditor,
34
+ isChromelessEditor,
31
35
  isTableHovered: false,
32
36
  insertColumnButtonIndex: undefined,
33
37
  insertRowButtonIndex: undefined,
@@ -117,8 +121,34 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
117
121
  }
118
122
  },
119
123
  view: editorView => {
124
+ var _pluginInjectionApi$e, _pluginInjectionApi$e2;
120
125
  const domAtPos = editorView.domAtPos.bind(editorView);
121
126
  editorViewRef = editorView;
127
+ let contentModeSizeTableId = null;
128
+ let focusListenerBinding = null;
129
+ if ((pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 ? void 0 : (_pluginInjectionApi$e2 = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e2 === void 0 ? void 0 : _pluginInjectionApi$e2.mode) !== 'view' && isContentModeSupported({
130
+ allowColumnResizing: !!pluginConfig.allowColumnResizing,
131
+ allowTableResizing: !!pluginConfig.allowTableResizing,
132
+ isFullPageEditor: !isChromelessEditor && !isCommentEditor
133
+ }) && expValEquals('platform_editor_table_fit_to_content_auto_convert', 'isEnabled', true)) {
134
+ focusListenerBinding = bind(editorView.dom, {
135
+ type: 'focus',
136
+ listener: () => {
137
+ if (contentModeSizeTableId) {
138
+ return;
139
+ }
140
+ contentModeSizeTableId = requestAnimationFrame(() => {
141
+ if (!editorViewRef) {
142
+ return;
143
+ }
144
+ applyMeasuredWidthToAllTables(editorViewRef, pluginInjectionApi);
145
+ });
146
+ },
147
+ options: {
148
+ once: true
149
+ }
150
+ });
151
+ }
122
152
  return {
123
153
  update: (view, prevState) => {
124
154
  const {
@@ -131,12 +161,12 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
131
161
  const pluginState = getPluginState(state);
132
162
  let tableRef;
133
163
  if (fg('platform_editor_enable_table_dnd')) {
134
- var _pluginInjectionApi$e, _pluginInjectionApi$e2;
164
+ var _pluginInjectionApi$e3, _pluginInjectionApi$e4;
135
165
  const parent = findParentDomRefOfType(state.schema.nodes.table, domAtPos)(selection);
136
- let shouldSetTableRef = fg('platform_editor_enable_table_dnd_patch_1') ? parent && (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 ? void 0 : (_pluginInjectionApi$e2 = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e2 === void 0 ? void 0 : _pluginInjectionApi$e2.mode) !== 'view' : parent;
166
+ let shouldSetTableRef = fg('platform_editor_enable_table_dnd_patch_1') ? parent && (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e3 = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e3 === void 0 ? void 0 : (_pluginInjectionApi$e4 = _pluginInjectionApi$e3.sharedState.currentState()) === null || _pluginInjectionApi$e4 === void 0 ? void 0 : _pluginInjectionApi$e4.mode) !== 'view' : parent;
137
167
  if (expValEquals('platform_editor_table_update_table_ref', 'isEnabled', true) && fg('platform_editor_update_table_ref_fix')) {
138
- var _pluginInjectionApi$e3, _pluginInjectionApi$e4, _pluginInjectionApi$i, _pluginInjectionApi$i2;
139
- shouldSetTableRef = parent && (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e3 = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e3 === void 0 ? void 0 : (_pluginInjectionApi$e4 = _pluginInjectionApi$e3.sharedState.currentState()) === null || _pluginInjectionApi$e4 === void 0 ? void 0 : _pluginInjectionApi$e4.mode) !== 'view' && (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$i = pluginInjectionApi.interaction) === null || _pluginInjectionApi$i === void 0 ? void 0 : (_pluginInjectionApi$i2 = _pluginInjectionApi$i.sharedState.currentState()) === null || _pluginInjectionApi$i2 === void 0 ? void 0 : _pluginInjectionApi$i2.interactionState) !== 'hasNotHadInteraction';
168
+ var _pluginInjectionApi$e5, _pluginInjectionApi$e6, _pluginInjectionApi$i, _pluginInjectionApi$i2;
169
+ shouldSetTableRef = parent && (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e5 = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e5 === void 0 ? void 0 : (_pluginInjectionApi$e6 = _pluginInjectionApi$e5.sharedState.currentState()) === null || _pluginInjectionApi$e6 === void 0 ? void 0 : _pluginInjectionApi$e6.mode) !== 'view' && (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$i = pluginInjectionApi.interaction) === null || _pluginInjectionApi$i === void 0 ? void 0 : (_pluginInjectionApi$i2 = _pluginInjectionApi$i.sharedState.currentState()) === null || _pluginInjectionApi$i2 === void 0 ? void 0 : _pluginInjectionApi$i2.interactionState) !== 'hasNotHadInteraction';
140
170
  }
141
171
  if (shouldSetTableRef) {
142
172
  tableRef =
@@ -199,6 +229,10 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
199
229
  } else if (pluginState.isResizeHandleWidgetAdded) {
200
230
  removeResizeHandleDecorations()(state, dispatch);
201
231
  }
232
+ },
233
+ destroy: () => {
234
+ contentModeSizeTableId && cancelAnimationFrame(contentModeSizeTableId);
235
+ focusListenerBinding && focusListenerBinding();
202
236
  }
203
237
  };
204
238
  },
@@ -12,6 +12,7 @@ import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorMaxWi
12
12
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
13
  import { TABLE_MAX_WIDTH, TABLE_FULL_WIDTH } from './table-resizing/utils/consts';
14
14
  import { ALIGN_START } from './utils/alignment';
15
+ import { isTableInContentMode } from './utils/tableMode';
15
16
  export const pluginKey = new PluginKey('tableWidthPlugin');
16
17
  const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, maxWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled, isCommentEditor) => {
17
18
  return new SafePlugin({
@@ -61,6 +62,15 @@ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, maxWid
61
62
  const tr = newState.tr;
62
63
  if (isReplaceDocumentOperation && !isCommentEditor) {
63
64
  newState.doc.forEach((node, offset) => {
65
+ if (isTableInContentMode({
66
+ node,
67
+ allowColumnResizing: true,
68
+ allowTableResizing: true,
69
+ isFullPageEditor: true,
70
+ isTableNested: false
71
+ })) {
72
+ return;
73
+ }
64
74
  if (node.type === table) {
65
75
  const width = node.attrs.width;
66
76
  const layout = node.attrs.layout;
@@ -0,0 +1,39 @@
1
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
+ import { akEditorFullWidthLayoutWidth, akEditorMaxLayoutWidth } from '@atlaskit/editor-shared-styles';
3
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
+ import { updateCellsMarkup } from './table-transform-utils';
5
+ const tableWidth = contentWidth => {
6
+ const maxEditorWidth = expValEquals('editor_tinymce_full_width_mode', 'isEnabled', true) || expValEquals('confluence_max_width_content_appearance', 'isEnabled', true) ? akEditorMaxLayoutWidth : akEditorFullWidthLayoutWidth;
7
+ return Math.min(maxEditorWidth, contentWidth);
8
+ };
9
+ export const getTableMeasurement = tableRef => {
10
+ const colWidths = getRenderedColgroupColumnWidths(tableRef);
11
+ const totalContentWidth = colWidths.reduce((acc, current) => acc + current, 0);
12
+ return {
13
+ colWidths,
14
+ tableWidth: tableWidth(totalContentWidth)
15
+ };
16
+ };
17
+ export const applyTableMeasurement = (tr, tableNode, {
18
+ colWidths,
19
+ tableWidth
20
+ }, tablePos) => {
21
+ tr = updateCellsMarkup(tr, tableNode, tablePos, (cell, _rowIndex, colIndex) => {
22
+ const newColWidths = colWidths.slice(colIndex, colIndex + cell.attrs.colspan);
23
+ return cell.type.createChecked({
24
+ ...cell.attrs,
25
+ colwidth: newColWidths.length ? newColWidths : null
26
+ }, cell.content, cell.marks);
27
+ });
28
+ return tr.setNodeMarkup(tablePos, undefined, {
29
+ ...tableNode.attrs,
30
+ width: tableWidth
31
+ });
32
+ };
33
+ function getRenderedColgroupColumnWidths(tableRef) {
34
+ const cols = Array.from(tableRef.querySelectorAll(':scope > colgroup > col'));
35
+ return cols.map(col => {
36
+ const width = col.getBoundingClientRect().width;
37
+ return Math.max(Math.round(width), tableCellMinWidth);
38
+ });
39
+ }
@@ -3,6 +3,7 @@ import { akEditorDefaultLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/e
3
3
  import { calculateColumnWidth, getCellsRefsInColumn } from '../table-resizing/utils/column-state';
4
4
  import { contentWidth } from '../table-resizing/utils/content-width';
5
5
  import { getLayoutSize } from '../table-resizing/utils/misc';
6
+ import { replaceCells } from './table-transform-utils';
6
7
  const validateTableCellNodeAttrs = ({
7
8
  colspan,
8
9
  rowspan,
@@ -153,36 +154,4 @@ function parseDOMColumnWidths(domAtPos, tableNode, tableStart, tableRef) {
153
154
  }
154
155
  }
155
156
  return cols;
156
- }
157
-
158
- // TODO: ED-26961 - move to prosemirror-utils
159
- const replaceCells = (tr, table, tablePos, modifyCell) => {
160
- const rows = [];
161
- let modifiedCells = 0;
162
- for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
163
- const row = table.child(rowIndex);
164
- const cells = [];
165
- for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
166
- const cell = row.child(colIndex);
167
-
168
- // TODO: ED-26961 - The rowIndex and colIndex are not accurate in a merged cell scenario
169
- // e.g. table with 5 columns might have only one cell in a row, colIndex will be 1, where it should be 4
170
- const node = modifyCell(cell, rowIndex, colIndex);
171
- if (node.sameMarkup(cell) === false) {
172
- modifiedCells++;
173
- }
174
- cells.push(node);
175
- }
176
- if (cells.length) {
177
- rows.push(row.type.createChecked(row.attrs, cells, row.marks));
178
- }
179
- }
180
-
181
- // Check if the table has changed before replacing.
182
- // If no cells are modified our counter will be zero.
183
- if (rows.length && modifiedCells !== 0) {
184
- const newTable = table.type.createChecked(table.attrs, rows, table.marks);
185
- return tr.replaceWith(tablePos, tablePos + table.nodeSize, newTable);
186
- }
187
- return tr;
188
- };
157
+ }
@@ -0,0 +1,56 @@
1
+ // TODO: ED-26961 - move to prosemirror-utils
2
+ export const replaceCells = (tr, table, tablePos, modifyCell) => {
3
+ const rows = [];
4
+ let modifiedCells = 0;
5
+ for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
6
+ const row = table.child(rowIndex);
7
+ const cells = [];
8
+ for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
9
+ const cell = row.child(colIndex);
10
+
11
+ // TODO: ED-26961 - The rowIndex and colIndex are not accurate in a merged cell scenario
12
+ // e.g. table with 5 columns might have only one cell in a row, colIndex will be 1, where it should be 4
13
+ const node = modifyCell(cell, rowIndex, colIndex);
14
+ if (node.sameMarkup(cell) === false) {
15
+ modifiedCells++;
16
+ }
17
+ cells.push(node);
18
+ }
19
+ if (cells.length) {
20
+ rows.push(row.type.createChecked(row.attrs, cells, row.marks));
21
+ }
22
+ }
23
+
24
+ // Check if the table has changed before replacing.
25
+ // If no cells are modified our counter will be zero.
26
+ if (rows.length && modifiedCells !== 0) {
27
+ const newTable = table.type.createChecked(table.attrs, rows, table.marks);
28
+ return tr.replaceWith(tablePos, tablePos + table.nodeSize, newTable);
29
+ }
30
+ return tr;
31
+ };
32
+
33
+ /**
34
+ * Position-preserving alternative to `replaceCells`.
35
+ *
36
+ * Uses `setNodeMarkup` per cell instead of rebuilding the whole table with
37
+ * `replaceWith`, so document positions inside cells are never invalidated.
38
+ * This preserves any existing selection through `tr.mapping`.
39
+ */
40
+ export const updateCellsMarkup = (tr, table, tablePos, modifyCell) => {
41
+ let rowOffset = tablePos + 1;
42
+ for (let rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
43
+ const row = table.child(rowIndex);
44
+ let cellOffset = rowOffset + 1;
45
+ for (let colIndex = 0; colIndex < row.childCount; colIndex++) {
46
+ const cell = row.child(colIndex);
47
+ const modified = modifyCell(cell, rowIndex, colIndex);
48
+ if (!modified.sameMarkup(cell)) {
49
+ tr.setNodeMarkup(cellOffset, modified.type, modified.attrs, modified.marks);
50
+ }
51
+ cellOffset += cell.nodeSize;
52
+ }
53
+ rowOffset += row.nodeSize;
54
+ }
55
+ return tr;
56
+ };
@@ -1,5 +1,5 @@
1
1
  import { createElement } from 'react';
2
- import { RawIntlProvider } from 'react-intl-next';
2
+ import { RawIntlProvider } from 'react-intl';
3
3
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
4
4
  import uuid from 'uuid/v4';
5
5
  import { nonNullable } from '@atlaskit/editor-common/utils';
@@ -0,0 +1,148 @@
1
+ import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
2
+ import { TableSharedCssClassName } from '@atlaskit/editor-common/styles';
3
+ import { findTable } from '@atlaskit/editor-tables/utils';
4
+ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
5
+ import { hasTableColumnBeenResized } from '../table-resizing/utils/colgroup';
6
+ import { applyTableMeasurement, getTableMeasurement } from '../transforms/content-mode';
7
+ import { ALIGN_START } from './alignment';
8
+ export const isTableInContentMode = ({
9
+ allowColumnResizing,
10
+ allowTableResizing,
11
+ isFullPageEditor,
12
+ isTableNested,
13
+ node
14
+ }) => {
15
+ if (!expValEqualsNoExposure('platform_editor_table_fit_to_content_auto_convert', 'isEnabled', true)) {
16
+ return false;
17
+ }
18
+ if (!node || isTableNested) {
19
+ return false;
20
+ }
21
+ return isContentModeSupported({
22
+ allowColumnResizing,
23
+ allowTableResizing,
24
+ isFullPageEditor
25
+ }) && !hasTableBeenResized(node) && node.attrs.layout === ALIGN_START;
26
+ };
27
+ export const isContentModeSupported = ({
28
+ allowColumnResizing,
29
+ allowTableResizing,
30
+ isFullPageEditor
31
+ }) => {
32
+ return allowColumnResizing && allowTableResizing && isFullPageEditor;
33
+ };
34
+ export const hasTableBeenResized = node => node.attrs.width !== null || hasTableColumnBeenResized(node);
35
+
36
+ /**
37
+ * Iterates all top-level tables in the document, and for those in content mode,
38
+ * measures rendered column widths and sets colwidth + table width attributes
39
+ * in a single batched transaction.
40
+ */
41
+ export const applyMeasuredWidthToAllTables = (view, pluginInjectionApi) => {
42
+ const {
43
+ state: {
44
+ doc,
45
+ schema
46
+ }
47
+ } = view;
48
+ let tr = view.state.tr;
49
+ const {
50
+ table
51
+ } = schema.nodes;
52
+ let modified = false;
53
+ const measuredTables = [];
54
+
55
+ // modify only top-level tables
56
+ doc.forEach((node, offset) => {
57
+ if (node.type !== table || hasTableBeenResized(node) && node.attrs.layout !== ALIGN_START) {
58
+ return;
59
+ }
60
+ const domNode = view.domAtPos(offset + 1).node;
61
+ const tableWrapper = domNode instanceof HTMLElement ? domNode.closest(`.${TableSharedCssClassName.TABLE_VIEW_CONTENT_WRAP}`) : null;
62
+ const tableRef = tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.querySelector('table');
63
+ if (!tableRef) {
64
+ return;
65
+ }
66
+ measuredTables.push({
67
+ node,
68
+ offset,
69
+ measurement: getTableMeasurement(tableRef)
70
+ });
71
+ });
72
+ measuredTables.forEach(({
73
+ node,
74
+ offset,
75
+ measurement
76
+ }) => {
77
+ tr = applyTableMeasurement(tr, node, measurement, offset);
78
+ modified = true;
79
+ });
80
+ if (modified) {
81
+ var _pluginInjectionApi$a, _pluginInjectionApi$a2, _pluginInjectionApi$w, _pluginInjectionApi$w2, _pluginInjectionApi$w3;
82
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : (_pluginInjectionApi$a2 = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.attachAnalyticsEvent({
83
+ action: TABLE_ACTION.FIT_TO_CONTENT_AUTO_CONVERTED,
84
+ actionSubject: ACTION_SUBJECT.TABLE,
85
+ actionSubjectId: null,
86
+ eventType: EVENT_TYPE.TRACK,
87
+ attributes: {
88
+ editorContainerWidth: (_pluginInjectionApi$w = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$w2 = pluginInjectionApi.width) === null || _pluginInjectionApi$w2 === void 0 ? void 0 : (_pluginInjectionApi$w3 = _pluginInjectionApi$w2.sharedState.currentState()) === null || _pluginInjectionApi$w3 === void 0 ? void 0 : _pluginInjectionApi$w3.width) !== null && _pluginInjectionApi$w !== void 0 ? _pluginInjectionApi$w : 0,
89
+ totalTablesResized: measuredTables.length,
90
+ measurements: measuredTables.map(({
91
+ measurement
92
+ }) => ({
93
+ tableWidth: measurement.tableWidth,
94
+ totalColumnCount: measurement.colWidths.length
95
+ }))
96
+ }
97
+ })(tr);
98
+ view.dispatch(tr.setMeta('addToHistory', false));
99
+ }
100
+ };
101
+ export const applyMeasuredWidthToSelectedTable = (view, api) => {
102
+ var _api$analytics, _api$analytics$action, _api$width$sharedStat, _api$width, _api$width$sharedStat2;
103
+ const tableObject = findTable(view.state.selection);
104
+ if (!tableObject) {
105
+ return;
106
+ }
107
+ const {
108
+ node,
109
+ pos
110
+ } = tableObject;
111
+ const tableState = api === null || api === void 0 ? void 0 : api.table.sharedState.currentState();
112
+ if (!(tableState !== null && tableState !== void 0 && tableState.tableRef)) {
113
+ return;
114
+ }
115
+ const tableRef = tableState.tableRef;
116
+
117
+ // Instead of dispatching a transaction to "strip widths" and then waiting
118
+ // for a rAF to measure natural column widths, instea directly update the DOM elements and
119
+ // take a measurement.
120
+ const cols = Array.from(tableRef.querySelectorAll(':scope > colgroup > col'));
121
+ const contentWrap = tableRef.closest(`.${TableSharedCssClassName.TABLE_VIEW_CONTENT_WRAP}`);
122
+ const resizerContainer = contentWrap === null || contentWrap === void 0 ? void 0 : contentWrap.querySelector(`.${TableSharedCssClassName.TABLE_RESIZER_CONTAINER}`);
123
+ const resizerItem = resizerContainer === null || resizerContainer === void 0 ? void 0 : resizerContainer.querySelector('.resizer-item.display-handle');
124
+ tableRef.style.width = '';
125
+ tableRef.style.tableLayout = 'auto';
126
+ cols.forEach(col => col.style.width = '');
127
+ if (resizerContainer) {
128
+ resizerContainer.style.width = 'max-content';
129
+ resizerContainer.style.setProperty('--ak-editor-table-width', 'max-content');
130
+ }
131
+ if (resizerItem) {
132
+ resizerItem.style.width = 'max-content';
133
+ }
134
+ const measurement = getTableMeasurement(tableRef);
135
+ const tr = applyTableMeasurement(view.state.tr, node, measurement, pos);
136
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : (_api$analytics$action = _api$analytics.actions) === null || _api$analytics$action === void 0 ? void 0 : _api$analytics$action.attachAnalyticsEvent({
137
+ action: TABLE_ACTION.FIT_TO_CONTENT_ON_DEMAND,
138
+ actionSubject: ACTION_SUBJECT.TABLE,
139
+ actionSubjectId: null,
140
+ eventType: EVENT_TYPE.TRACK,
141
+ attributes: {
142
+ editorContainerWidth: (_api$width$sharedStat = api === null || api === void 0 ? void 0 : (_api$width = api.width) === null || _api$width === void 0 ? void 0 : (_api$width$sharedStat2 = _api$width.sharedState.currentState()) === null || _api$width$sharedStat2 === void 0 ? void 0 : _api$width$sharedStat2.width) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : 0,
143
+ tableWidth: measurement.tableWidth,
144
+ totalColumnCount: measurement.colWidths.length
145
+ }
146
+ })(tr);
147
+ view.dispatch(tr);
148
+ };
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { createElement } from 'react';
8
- import { RawIntlProvider } from 'react-intl-next';
8
+ import { RawIntlProvider } from 'react-intl';
9
9
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
10
10
  import uuid from 'uuid/v4';
11
11
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
@@ -5,7 +5,7 @@ import _extends from "@babel/runtime/helpers/extends";
5
5
  */
6
6
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
7
  import { jsx } from '@emotion/react';
8
- import { useIntl } from 'react-intl-next';
8
+ import { useIntl } from 'react-intl';
9
9
  import { startColumnResizing, ToolTipContent } from '@atlaskit/editor-common/keymaps';
10
10
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
11
11
  import Tooltip from '@atlaskit/tooltip';
@@ -3,7 +3,7 @@
3
3
  import React, { useEffect, useMemo, useRef, useState } from 'react';
4
4
  import classnames from 'classnames';
5
5
  import ReactDOM from 'react-dom';
6
- import { injectIntl } from 'react-intl-next';
6
+ import { injectIntl } from 'react-intl';
7
7
  import { getBrowserInfo } from '@atlaskit/editor-common/browser';
8
8
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
9
9
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
@@ -5,7 +5,7 @@
5
5
  import React, { useEffect } from 'react';
6
6
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
7
  import { css, jsx } from '@emotion/react';
8
- import { injectIntl } from 'react-intl-next';
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
11
  import { focusToContextMenuTrigger } from '@atlaskit/editor-common/keymaps';
@@ -7,7 +7,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
7
  import React, { Component } from 'react';
8
8
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
9
  import { jsx } from '@emotion/react';
10
- import { injectIntl } from 'react-intl-next';
10
+ import { injectIntl } from 'react-intl';
11
11
  import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
12
12
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
13
13
  import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { injectIntl } from 'react-intl-next';
2
+ import { injectIntl } from 'react-intl';
3
3
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
4
  import { TableCssClassName as ClassName } from '../../types';
5
5
  const DeleteButton = ({
@@ -8,7 +8,7 @@ import React, { useEffect, useState } from 'react';
8
8
 
9
9
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
10
10
  import { jsx } from '@emotion/react';
11
- import { injectIntl } from 'react-intl-next';
11
+ import { injectIntl } from 'react-intl';
12
12
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
13
13
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
14
14
  import { DropdownMenuSharedCssClassName } from '@atlaskit/editor-common/styles';
@@ -2,7 +2,7 @@
2
2
 
3
3
  import React from 'react';
4
4
  import classnames from 'classnames';
5
- import { injectIntl } from 'react-intl-next';
5
+ import { injectIntl } from 'react-intl';
6
6
  import { addColumnAfter, addRowAfter, ToolTipContent } from '@atlaskit/editor-common/keymaps';
7
7
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
8
8
  import { tableMarginTop } from '@atlaskit/editor-common/styles';
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import React from 'react';
4
- import { injectIntl } from 'react-intl-next';
4
+ import { injectIntl } from 'react-intl';
5
5
  import { ACTION, ACTION_SUBJECT, CONTENT_COMPONENT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
6
  import { Popup } from '@atlaskit/editor-common/ui';
7
7
  import { closestElement } from '@atlaskit/editor-common/utils';
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React, { Component } from 'react';
3
3
  import classnames from 'classnames';
4
- import { injectIntl } from 'react-intl-next';
4
+ import { injectIntl } from 'react-intl';
5
5
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
7
  import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
@@ -1,6 +1,6 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import classnames from 'classnames';
3
- import { injectIntl } from 'react-intl-next';
3
+ import { injectIntl } from 'react-intl';
4
4
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
5
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
6
  import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React, { Component } from 'react';
3
- import { injectIntl } from 'react-intl-next';
3
+ import { injectIntl } from 'react-intl';
4
4
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
5
5
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
6
6
  import { clearHoverSelection } from '../../../pm-plugins/commands';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { useIntl } from 'react-intl-next';
2
+ import { useIntl } from 'react-intl';
3
3
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
4
  // eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
5
5
  import { Box, Inline, xcss } from '@atlaskit/primitives';
@@ -1,7 +1,8 @@
1
1
  import rafSchedule from 'raf-schd';
2
2
  import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
3
+ import { getBrowserInfo } from '@atlaskit/editor-common/browser';
3
4
  import { getParentOfTypeCount } from '@atlaskit/editor-common/nesting';
4
- import { browser, closestElement, isElementInTableCell, isLastItemMediaGroup, setNodeSelection } from '@atlaskit/editor-common/utils';
5
+ import { closestElement, isElementInTableCell, isLastItemMediaGroup, setNodeSelection } from '@atlaskit/editor-common/utils';
5
6
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
6
7
  import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
7
8
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
@@ -30,7 +31,7 @@ export const handleBlur = (view, event) => {
30
31
  } = view;
31
32
  // IE version check for ED-4665
32
33
  // Calendar focus check for ED-10466
33
- if (browser.ie_version !== 11 && !isFocusingCalendar(event) && !isFocusingModal(event) && !isFocusingFloatingToolbar(event) && !isFocusingDragHandles(event) && !isFocusingDragHandlesClickableZone(event)) {
34
+ if (getBrowserInfo().ie_version !== 11 && !isFocusingCalendar(event) && !isFocusingModal(event) && !isFocusingFloatingToolbar(event) && !isFocusingDragHandles(event) && !isFocusingDragHandlesClickableZone(event)) {
34
35
  setEditorFocus(false)(state, dispatch);
35
36
  }
36
37
  event.preventDefault();
@@ -361,7 +362,7 @@ export const handleMouseMove = nodeViewPortalProviderAPI => (view, event) => {
361
362
  // a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
362
363
  // in the deferred callback handler.
363
364
  // Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
364
- handleMouseMoveDebounce(nodeViewPortalProviderAPI)(view, event, browser.gecko ? event.offsetX : NaN);
365
+ handleMouseMoveDebounce(nodeViewPortalProviderAPI)(view, event, getBrowserInfo().gecko ? event.offsetX : NaN);
365
366
  return false;
366
367
  };
367
368
  export function handleTripleClick(view, pos) {
@@ -27,6 +27,7 @@ import AlignImageLeftIcon from '@atlaskit/icon/core/align-image-left';
27
27
  import CopyIcon from '@atlaskit/icon/core/copy';
28
28
  import CustomizeIcon from '@atlaskit/icon/core/customize';
29
29
  import DeleteIcon from '@atlaskit/icon/core/delete';
30
+ import ShrinkHorizontalIcon from '@atlaskit/icon/core/shrink-horizontal';
30
31
  import TableColumnsDistributeIcon from '@atlaskit/icon/core/table-columns-distribute';
31
32
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
32
33
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -43,6 +44,7 @@ import { normaliseAlignment } from '../pm-plugins/utils/alignment';
43
44
  import { isTableNested } from '../pm-plugins/utils/nodes';
44
45
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../pm-plugins/utils/selection';
45
46
  import { getMergedCellsPositions } from '../pm-plugins/utils/table';
47
+ import { applyMeasuredWidthToSelectedTable, isContentModeSupported } from '../pm-plugins/utils/tableMode';
46
48
  import { TableCssClassName } from '../types';
47
49
  import { FloatingAlignmentButtons } from './FloatingAlignmentButtons/FloatingAlignmentButtons';
48
50
  export const getToolbarMenuConfig = (config, state, {
@@ -425,7 +427,7 @@ export const getToolbarConfig = (getEditorContainerWidth, api, editorAnalyticsAP
425
427
  // We don't want to show floating toolbar while resizing the table
426
428
  const isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
427
429
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
428
- var _api$limitedMode$shar, _api$limitedMode, _api$limitedMode$shar2, _api$extension, _api$extension$shared, _api$extension2;
430
+ var _api$limitedMode$shar, _api$limitedMode, _api$limitedMode$shar2, _api$editorViewMode2, _api$editorViewMode2$, _api$extension, _api$extension$shared, _api$extension2;
429
431
  const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
430
432
  const isTableScalingWithFixedColumnWidthsOptionShown = isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && !isNested;
431
433
  const areTableColumWidthsFixed = tableObject.node.attrs.displayMode === 'fixed';
@@ -455,6 +457,25 @@ export const getToolbarConfig = (getEditorContainerWidth, api, editorAnalyticsAP
455
457
  const cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, editorView, intl, getEditorContainerWidth, api, editorAnalyticsAPI, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, options === null || options === void 0 ? void 0 : options.isCommentEditor, isLimitedModeEnabled);
456
458
  const columnSettingsItems = pluginState.isDragAndDropEnabled ? getColumnSettingItems(state, editorView, intl, getEditorContainerWidth, api, editorAnalyticsAPI, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, options === null || options === void 0 ? void 0 : options.isCommentEditor, isLimitedModeEnabled) : [];
457
459
  const colorPicker = !areAnyNewToolbarFlagsEnabled ? getColorPicker(state, menu, intl, editorAnalyticsAPI, getEditorView) : [];
460
+ const fitToContentButton = isContentModeSupported({
461
+ allowColumnResizing: !!pluginState.pluginConfig.allowColumnResizing,
462
+ allowTableResizing: !!pluginState.pluginConfig.allowTableResizing,
463
+ isFullPageEditor: !pluginState.isChromelessEditor && !pluginState.isCommentEditor
464
+ }) && !isNested && (api === null || api === void 0 ? void 0 : (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 ? void 0 : (_api$editorViewMode2$ = _api$editorViewMode2.sharedState.currentState()) === null || _api$editorViewMode2$ === void 0 ? void 0 : _api$editorViewMode2$.mode) !== 'view' && expValEquals('platform_editor_table_fit_to_content_on_demand', 'isEnabled', true) ? [{
465
+ id: 'editor.table.fitToContent',
466
+ type: 'button',
467
+ title: intl.formatMessage(messages.fitToContent),
468
+ icon: () => jsx(ShrinkHorizontalIcon, {
469
+ spacing: 'spacious',
470
+ label: ''
471
+ }),
472
+ onClick: (_state, _dispatch, view) => {
473
+ if (view) {
474
+ applyMeasuredWidthToSelectedTable(view, api !== null && api !== void 0 ? api : undefined);
475
+ }
476
+ return true;
477
+ }
478
+ }] : [];
458
479
 
459
480
  // Check if we need to show confirm dialog for delete button
460
481
  let confirmDialog;
@@ -524,7 +545,7 @@ export const getToolbarConfig = (getEditorContainerWidth, api, editorAnalyticsAP
524
545
  },
525
546
  zIndex: akEditorFloatingPanelZIndex + 1,
526
547
  // Place the context menu slightly above the others
527
- items: [menu, ...(!areAnyNewToolbarFlagsEnabled ? [separator(menu.hidden)] : []), ...alignmentMenu, ...(!areAnyNewToolbarFlagsEnabled ? [separator(alignmentMenu.length === 0)] : []), ...cellItems, ...columnSettingsItems, ...colorPicker, ...(!areAnyNewToolbarFlagsEnabled ? [{
548
+ items: [menu, ...(!areAnyNewToolbarFlagsEnabled ? [separator(menu.hidden)] : []), ...alignmentMenu, ...(!areAnyNewToolbarFlagsEnabled ? [separator(alignmentMenu.length === 0)] : []), ...cellItems, ...columnSettingsItems, ...fitToContentButton, ...colorPicker, ...(!areAnyNewToolbarFlagsEnabled ? [{
528
549
  type: 'extensions-placeholder',
529
550
  separator: 'end'
530
551
  }, copyButton, {
@@ -15,7 +15,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
15
15
  import React from 'react';
16
16
  import classnames from 'classnames';
17
17
  import rafSchedule from 'raf-schd';
18
- import { injectIntl } from 'react-intl-next';
18
+ import { injectIntl } from 'react-intl';
19
19
  import { getBrowserInfo } from '@atlaskit/editor-common/browser';
20
20
  import { tintDirtyTransaction } from '@atlaskit/editor-common/collab';
21
21
  import { getParentOfTypeCount } from '@atlaskit/editor-common/nesting';