@atlaskit/editor-plugin-table 5.7.1 → 5.7.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.7.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#63416](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/63416) [`cfa23683ae92`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cfa23683ae92) - update floating tool bar button
8
+ - [#63569](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/63569) [`bf5ed730bc99`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bf5ed730bc99) - Use start position to calculate insert column buttons to cater for merged cells
9
+
3
10
  ## 5.7.1
4
11
 
5
12
  ### Patch Changes
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.getToolbarMenuConfig = exports.getToolbarConfig = exports.getToolbarCellOptionsConfig = exports.getClosestSelectionRect = void 0;
8
+ exports.getToolbarMenuConfig = exports.getToolbarConfig = exports.getToolbarCellOptionsConfig = exports.getDistributeConfig = exports.getClosestSelectionRect = exports.getClosestSelectionOrTableRect = void 0;
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _react = require("@emotion/react");
11
11
  var _customSteps = require("@atlaskit/custom-steps");
@@ -17,8 +17,12 @@ var _utils = require("@atlaskit/editor-common/utils");
17
17
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
18
18
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
19
19
  var _shortcut = require("@atlaskit/editor-shared-styles/shortcut");
20
+ var _tableMap = require("@atlaskit/editor-tables/table-map");
20
21
  var _utils3 = require("@atlaskit/editor-tables/utils");
22
+ var _layoutThreeEqual = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/layout-three-equal"));
21
23
  var _remove = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/remove"));
24
+ var _preferences = _interopRequireDefault(require("@atlaskit/icon/glyph/preferences"));
25
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
22
26
  var _commands = require("./commands");
23
27
  var _commandsWithAnalytics = require("./commands-with-analytics");
24
28
  var _pluginFactory = require("./pm-plugins/plugin-factory");
@@ -60,16 +64,30 @@ var getToolbarMenuConfig = exports.getToolbarMenuConfig = function getToolbarMen
60
64
  disabled: !state.canCollapseTable,
61
65
  hidden: !config.allowCollapse
62
66
  }];
63
- return {
64
- id: 'editor.table.tableOptions',
65
- type: 'dropdown',
66
- testId: 'table_options',
67
- title: formatMessage(_messages.tableMessages.tableOptions),
68
- hidden: options.every(function (option) {
69
- return option.hidden;
70
- }),
71
- options: options
72
- };
67
+ if (state.isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling')) {
68
+ return {
69
+ id: 'editor.table.tableOptions',
70
+ type: 'dropdown',
71
+ testId: 'table_options',
72
+ icon: _preferences.default,
73
+ title: formatMessage(_messages.tableMessages.tableOptions),
74
+ hidden: options.every(function (option) {
75
+ return option.hidden;
76
+ }),
77
+ options: options
78
+ };
79
+ } else {
80
+ return {
81
+ id: 'editor.table.tableOptions',
82
+ type: 'dropdown',
83
+ testId: 'table_options',
84
+ title: formatMessage(_messages.tableMessages.tableOptions),
85
+ hidden: options.every(function (option) {
86
+ return option.hidden;
87
+ }),
88
+ options: options
89
+ };
90
+ }
73
91
  };
74
92
 
75
93
  // Added these options for mobile. Mobile bridge translates this menu and
@@ -268,6 +286,16 @@ var getClosestSelectionRect = exports.getClosestSelectionRect = function getClos
268
286
  var selection = state.selection;
269
287
  return (0, _utils3.isSelectionType)(selection, 'cell') ? (0, _utils3.getSelectionRect)(selection) : (0, _utils3.findCellRectClosestToPos)(selection.$from);
270
288
  };
289
+ var getClosestSelectionOrTableRect = exports.getClosestSelectionOrTableRect = function getClosestSelectionOrTableRect(state) {
290
+ var selection = state.selection;
291
+ var tableObject = (0, _utils3.findTable)(state.selection);
292
+ if (!tableObject) {
293
+ return;
294
+ }
295
+ var map = _tableMap.TableMap.get(tableObject.node);
296
+ var tableRect = new _tableMap.Rect(0, 0, map.width, map.height);
297
+ return (0, _utils3.isSelectionType)(selection, 'cell') ? (0, _utils3.getSelectionRect)(selection) : tableRect;
298
+ };
271
299
  var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, getEditorView) {
272
300
  return function (config) {
273
301
  return function (state, intl) {
@@ -283,6 +311,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
283
311
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
284
312
  var cellItems;
285
313
  cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI);
314
+ var columnSettingsItems;
315
+ columnSettingsItems = pluginState.isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI) : [];
286
316
  var colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
287
317
 
288
318
  // Check if we need to show confirm dialog for delete button
@@ -335,7 +365,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
335
365
  },
336
366
  zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex + 1,
337
367
  // Place the context menu slightly above the others
338
- items: [menu, separator(menu.hidden)].concat((0, _toConsumableArray2.default)(cellItems), colorPicker, [{
368
+ items: [menu, separator(menu.hidden)].concat((0, _toConsumableArray2.default)(cellItems), (0, _toConsumableArray2.default)(columnSettingsItems), colorPicker, [{
339
369
  type: 'extensions-placeholder',
340
370
  separator: 'end'
341
371
  }, {
@@ -390,9 +420,52 @@ var getCellItems = function getCellItems(pluginConfig, state, view, _ref3, getEd
390
420
  }
391
421
  return [];
392
422
  };
393
- var getColorPicker = function getColorPicker(state, menu, _ref4, editorAnalyticsAPI) {
394
- var _node$attrs;
423
+ var getDistributeConfig = exports.getDistributeConfig = function getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI) {
424
+ return function (state, dispatch, editorView) {
425
+ var selectionOrTableRect = getClosestSelectionOrTableRect(state);
426
+ if (!editorView || !selectionOrTableRect) {
427
+ return false;
428
+ }
429
+ var newResizeStateWithAnalytics = (0, _resizeState.getNewResizeStateFromSelectedColumns)(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
430
+ if (newResizeStateWithAnalytics) {
431
+ (0, _commandsWithAnalytics.distributeColumnsWidthsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.FLOATING_TB, newResizeStateWithAnalytics)(state, dispatch);
432
+ return true;
433
+ }
434
+ return false;
435
+ };
436
+ };
437
+
438
+ // this create the button group for distribute column and also fixed column width
439
+ // fixed column button should be in this function call in the future
440
+ var getColumnSettingItems = function getColumnSettingItems(editorState, editorView, _ref4, getEditorContainerWidth, editorAnalyticsAPI) {
441
+ var _newResizeStateWithAn2, _pluginState$pluginCo3;
395
442
  var formatMessage = _ref4.formatMessage;
443
+ var pluginState = (0, _pluginFactory.getPluginState)(editorState);
444
+ var selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
445
+ if (!selectionOrTableRect || !editorView) {
446
+ return [];
447
+ }
448
+ var newResizeStateWithAnalytics = (0, _resizeState.getNewResizeStateFromSelectedColumns)(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
449
+ var wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
450
+ if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo3 = pluginState.pluginConfig) !== null && _pluginState$pluginCo3 !== void 0 && _pluginState$pluginCo3.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
451
+ return [{
452
+ id: 'editor.table.distributeColumns',
453
+ type: 'button',
454
+ title: formatMessage(_messages.tableMessages.distributeColumns),
455
+ icon: _layoutThreeEqual.default,
456
+ onClick: function onClick(state, dispatch, view) {
457
+ return getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI)(state, dispatch, view);
458
+ },
459
+ disabled: !wouldChange
460
+ }, {
461
+ type: 'separator'
462
+ }];
463
+ }
464
+ return [];
465
+ };
466
+ var getColorPicker = function getColorPicker(state, menu, _ref5, editorAnalyticsAPI) {
467
+ var _node$attrs;
468
+ var formatMessage = _ref5.formatMessage;
396
469
  var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
397
470
  targetCellPosition = _getPluginState2.targetCellPosition,
398
471
  pluginConfig = _getPluginState2.pluginConfig;
@@ -29,7 +29,7 @@ var getSelectedColumns = function getSelectedColumns(selection) {
29
29
  return [];
30
30
  };
31
31
  var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
32
- var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
32
+ var _colWidths$map$join, _rowHeights$;
33
33
  var editorView = _ref.editorView,
34
34
  tableActive = _ref.tableActive,
35
35
  tableRef = _ref.tableRef,
@@ -104,16 +104,16 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
104
104
  var colIndexes = (0, _react.useMemo)(function () {
105
105
  return [colIndex];
106
106
  }, [colIndex]);
107
- var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
108
- return sum + cur;
109
- }, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
110
107
  var generateHandleByType = function generateHandleByType(type) {
111
- var _colWidths;
108
+ var _rowHeights$reduce, _colWidths;
112
109
  if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
113
110
  return null;
114
111
  }
115
112
  var isHover = type === 'hover';
116
113
  var isColumnsSelected = selectedColIndexes.length > 0;
114
+ var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
115
+ return sum + cur;
116
+ }, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
117
117
  var showCondition = isHover ? isColumnsSelected && !selectedColIndexes.includes(colIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : selectedColIndexes.length < (colWidths === null || colWidths === void 0 ? void 0 : colWidths.length) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
118
118
  if (!showCondition) {
119
119
  return null;
@@ -121,15 +121,15 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
121
121
  var gridColumnPosition = "".concat(colIndex + 1, " / span 1");
122
122
  var selectedColumnPosition = "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
123
123
  var hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
124
- var currentSelectionApprearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
125
- var istSelecting = isColumnsSelected && !isHover;
124
+ var currentSelectionAppearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
125
+ var isSelecting = isColumnsSelected && !isHover;
126
126
 
127
127
  // this indexes are used to calculate the drag and drop source
128
128
  var indexes = isColumnsSelected ? isHover ? colIndexes : selectedColIndexes : colIndexes;
129
129
  return showCondition && /*#__PURE__*/_react.default.createElement("div", {
130
130
  key: type,
131
131
  style: {
132
- gridColumn: istSelecting ? selectedColumnPosition : gridColumnPosition,
132
+ gridColumn: isSelecting ? selectedColumnPosition : gridColumnPosition,
133
133
  display: 'flex',
134
134
  justifyContent: 'center',
135
135
  alignItems: 'center',
@@ -147,7 +147,7 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
147
147
  forceDefaultHandle: isHover ? false : isColumnsSelected,
148
148
  previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : _styles.tableCellMinWidth,
149
149
  previewHeight: previewHeight,
150
- appearance: istSelecting ? currentSelectionApprearance : hoveredAppearance,
150
+ appearance: isSelecting ? currentSelectionAppearance : hoveredAppearance,
151
151
  onClick: handleClick,
152
152
  onMouseOver: handleMouseOver,
153
153
  onMouseOut: handleMouseOut,
@@ -181,7 +181,7 @@ var ColumnControls = exports.ColumnControls = function ColumnControls(_ref) {
181
181
  endIndex = _ref2.endIndex;
182
182
  return /*#__PURE__*/_react.default.createElement("div", {
183
183
  style: {
184
- gridColumn: "".concat(index + 1, " / span 1")
184
+ gridColumn: "".concat(startIndex + 1, " / span 1")
185
185
  },
186
186
  "data-start-index": startIndex,
187
187
  "data-end-index": endIndex,
@@ -9,8 +9,12 @@ import { closestElement, getChildrenInfo, getNodeName, isReferencedSource } from
9
9
  import { findParentDomRefOfType } from '@atlaskit/editor-prosemirror/utils';
10
10
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
11
11
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
12
+ import { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
12
13
  import { findCellRectClosestToPos, findTable, getSelectionRect, isSelectionType, splitCell } from '@atlaskit/editor-tables/utils';
14
+ import DistributeColumnIcon from '@atlaskit/icon/glyph/editor/layout-three-equal';
13
15
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
16
+ import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
17
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
18
  import { clearHoverSelection, hoverColumns, hoverMergedCells, hoverRows, hoverTable, removeDescendantNodes } from './commands';
15
19
  import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
16
20
  import { getPluginState } from './pm-plugins/plugin-factory';
@@ -49,14 +53,26 @@ export const getToolbarMenuConfig = (config, state, {
49
53
  disabled: !state.canCollapseTable,
50
54
  hidden: !config.allowCollapse
51
55
  }];
52
- return {
53
- id: 'editor.table.tableOptions',
54
- type: 'dropdown',
55
- testId: 'table_options',
56
- title: formatMessage(messages.tableOptions),
57
- hidden: options.every(option => option.hidden),
58
- options
59
- };
56
+ if (state.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling')) {
57
+ return {
58
+ id: 'editor.table.tableOptions',
59
+ type: 'dropdown',
60
+ testId: 'table_options',
61
+ icon: TableOptionsIcon,
62
+ title: formatMessage(messages.tableOptions),
63
+ hidden: options.every(option => option.hidden),
64
+ options
65
+ };
66
+ } else {
67
+ return {
68
+ id: 'editor.table.tableOptions',
69
+ type: 'dropdown',
70
+ testId: 'table_options',
71
+ title: formatMessage(messages.tableOptions),
72
+ hidden: options.every(option => option.hidden),
73
+ options
74
+ };
75
+ }
60
76
  };
61
77
 
62
78
  // Added these options for mobile. Mobile bridge translates this menu and
@@ -259,6 +275,16 @@ export const getClosestSelectionRect = state => {
259
275
  const selection = state.selection;
260
276
  return isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
261
277
  };
278
+ export const getClosestSelectionOrTableRect = state => {
279
+ const selection = state.selection;
280
+ const tableObject = findTable(state.selection);
281
+ if (!tableObject) {
282
+ return;
283
+ }
284
+ const map = TableMap.get(tableObject.node);
285
+ const tableRect = new Rect(0, 0, map.width, map.height);
286
+ return isSelectionType(selection, 'cell') ? getSelectionRect(selection) : tableRect;
287
+ };
262
288
  export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, getEditorView) => config => (state, intl) => {
263
289
  const tableObject = findTable(state.selection);
264
290
  const pluginState = getPluginState(state);
@@ -272,6 +298,8 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
272
298
  const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
273
299
  let cellItems;
274
300
  cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI);
301
+ let columnSettingsItems;
302
+ columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI) : [];
275
303
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
276
304
 
277
305
  // Check if we need to show confirm dialog for delete button
@@ -318,7 +346,7 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
318
346
  },
319
347
  zIndex: akEditorFloatingPanelZIndex + 1,
320
348
  // Place the context menu slightly above the others
321
- items: [menu, separator(menu.hidden), ...cellItems, ...colorPicker, {
349
+ items: [menu, separator(menu.hidden), ...cellItems, ...columnSettingsItems, ...colorPicker, {
322
350
  type: 'extensions-placeholder',
323
351
  separator: 'end'
324
352
  }, {
@@ -372,6 +400,46 @@ const getCellItems = (pluginConfig, state, view, {
372
400
  }
373
401
  return [];
374
402
  };
403
+ export const getDistributeConfig = (getEditorContainerWidth, editorAnalyticsAPI) => (state, dispatch, editorView) => {
404
+ const selectionOrTableRect = getClosestSelectionOrTableRect(state);
405
+ if (!editorView || !selectionOrTableRect) {
406
+ return false;
407
+ }
408
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
409
+ if (newResizeStateWithAnalytics) {
410
+ distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, newResizeStateWithAnalytics)(state, dispatch);
411
+ return true;
412
+ }
413
+ return false;
414
+ };
415
+
416
+ // this create the button group for distribute column and also fixed column width
417
+ // fixed column button should be in this function call in the future
418
+ const getColumnSettingItems = (editorState, editorView, {
419
+ formatMessage
420
+ }, getEditorContainerWidth, editorAnalyticsAPI) => {
421
+ var _newResizeStateWithAn2, _pluginState$pluginCo3;
422
+ const pluginState = getPluginState(editorState);
423
+ const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
424
+ if (!selectionOrTableRect || !editorView) {
425
+ return [];
426
+ }
427
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
428
+ const wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
429
+ if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo3 = pluginState.pluginConfig) !== null && _pluginState$pluginCo3 !== void 0 && _pluginState$pluginCo3.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
430
+ return [{
431
+ id: 'editor.table.distributeColumns',
432
+ type: 'button',
433
+ title: formatMessage(messages.distributeColumns),
434
+ icon: DistributeColumnIcon,
435
+ onClick: (state, dispatch, view) => getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI)(state, dispatch, view),
436
+ disabled: !wouldChange
437
+ }, {
438
+ type: 'separator'
439
+ }];
440
+ }
441
+ return [];
442
+ };
375
443
  const getColorPicker = (state, menu, {
376
444
  formatMessage
377
445
  }, editorAnalyticsAPI) => {
@@ -34,7 +34,7 @@ export const ColumnControls = ({
34
34
  isTableHovered,
35
35
  canDrag
36
36
  }) => {
37
- var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
37
+ var _colWidths$map$join, _rowHeights$;
38
38
  const widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(width => width ? `${width - 1}px` : '0px').join(' ')) !== null && _colWidths$map$join !== void 0 ? _colWidths$map$join : '0px';
39
39
  // TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
40
40
  const columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
@@ -104,14 +104,14 @@ export const ColumnControls = ({
104
104
  const colIndexes = useMemo(() => {
105
105
  return [colIndex];
106
106
  }, [colIndex]);
107
- const previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce((sum, cur) => sum + cur, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
108
107
  const generateHandleByType = type => {
109
- var _colWidths;
108
+ var _rowHeights$reduce, _colWidths;
110
109
  if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
111
110
  return null;
112
111
  }
113
112
  const isHover = type === 'hover';
114
113
  const isColumnsSelected = selectedColIndexes.length > 0;
114
+ const previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce((sum, cur) => sum + cur, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
115
115
  const showCondition = isHover ? isColumnsSelected && !selectedColIndexes.includes(colIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : selectedColIndexes.length < (colWidths === null || colWidths === void 0 ? void 0 : colWidths.length) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
116
116
  if (!showCondition) {
117
117
  return null;
@@ -119,15 +119,15 @@ export const ColumnControls = ({
119
119
  const gridColumnPosition = `${colIndex + 1} / span 1`;
120
120
  const selectedColumnPosition = `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`;
121
121
  const hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
122
- const currentSelectionApprearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
123
- const istSelecting = isColumnsSelected && !isHover;
122
+ const currentSelectionAppearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
123
+ const isSelecting = isColumnsSelected && !isHover;
124
124
 
125
125
  // this indexes are used to calculate the drag and drop source
126
126
  const indexes = isColumnsSelected ? isHover ? colIndexes : selectedColIndexes : colIndexes;
127
127
  return showCondition && /*#__PURE__*/React.createElement("div", {
128
128
  key: type,
129
129
  style: {
130
- gridColumn: istSelecting ? selectedColumnPosition : gridColumnPosition,
130
+ gridColumn: isSelecting ? selectedColumnPosition : gridColumnPosition,
131
131
  display: 'flex',
132
132
  justifyContent: 'center',
133
133
  alignItems: 'center',
@@ -145,7 +145,7 @@ export const ColumnControls = ({
145
145
  forceDefaultHandle: isHover ? false : isColumnsSelected,
146
146
  previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
147
147
  previewHeight: previewHeight,
148
- appearance: istSelecting ? currentSelectionApprearance : hoveredAppearance,
148
+ appearance: isSelecting ? currentSelectionAppearance : hoveredAppearance,
149
149
  onClick: handleClick,
150
150
  onMouseOver: handleMouseOver,
151
151
  onMouseOut: handleMouseOut,
@@ -179,7 +179,7 @@ export const ColumnControls = ({
179
179
  endIndex
180
180
  }, index) => /*#__PURE__*/React.createElement("div", {
181
181
  style: {
182
- gridColumn: `${index + 1} / span 1`
182
+ gridColumn: `${startIndex + 1} / span 1`
183
183
  },
184
184
  "data-start-index": startIndex,
185
185
  "data-end-index": endIndex,
@@ -10,8 +10,12 @@ import { closestElement, getChildrenInfo as _getChildrenInfo, getNodeName, isRef
10
10
  import { findParentDomRefOfType } from '@atlaskit/editor-prosemirror/utils';
11
11
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
12
12
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
13
+ import { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
13
14
  import { findCellRectClosestToPos, findTable, getSelectionRect, isSelectionType, splitCell } from '@atlaskit/editor-tables/utils';
15
+ import DistributeColumnIcon from '@atlaskit/icon/glyph/editor/layout-three-equal';
14
16
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
17
+ import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
18
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
15
19
  import { clearHoverSelection, hoverColumns, hoverMergedCells, hoverRows, hoverTable, removeDescendantNodes } from './commands';
16
20
  import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
17
21
  import { getPluginState } from './pm-plugins/plugin-factory';
@@ -49,16 +53,30 @@ export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _
49
53
  disabled: !state.canCollapseTable,
50
54
  hidden: !config.allowCollapse
51
55
  }];
52
- return {
53
- id: 'editor.table.tableOptions',
54
- type: 'dropdown',
55
- testId: 'table_options',
56
- title: formatMessage(messages.tableOptions),
57
- hidden: options.every(function (option) {
58
- return option.hidden;
59
- }),
60
- options: options
61
- };
56
+ if (state.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling')) {
57
+ return {
58
+ id: 'editor.table.tableOptions',
59
+ type: 'dropdown',
60
+ testId: 'table_options',
61
+ icon: TableOptionsIcon,
62
+ title: formatMessage(messages.tableOptions),
63
+ hidden: options.every(function (option) {
64
+ return option.hidden;
65
+ }),
66
+ options: options
67
+ };
68
+ } else {
69
+ return {
70
+ id: 'editor.table.tableOptions',
71
+ type: 'dropdown',
72
+ testId: 'table_options',
73
+ title: formatMessage(messages.tableOptions),
74
+ hidden: options.every(function (option) {
75
+ return option.hidden;
76
+ }),
77
+ options: options
78
+ };
79
+ }
62
80
  };
63
81
 
64
82
  // Added these options for mobile. Mobile bridge translates this menu and
@@ -257,6 +275,16 @@ export var getClosestSelectionRect = function getClosestSelectionRect(state) {
257
275
  var selection = state.selection;
258
276
  return isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
259
277
  };
278
+ export var getClosestSelectionOrTableRect = function getClosestSelectionOrTableRect(state) {
279
+ var selection = state.selection;
280
+ var tableObject = findTable(state.selection);
281
+ if (!tableObject) {
282
+ return;
283
+ }
284
+ var map = TableMap.get(tableObject.node);
285
+ var tableRect = new Rect(0, 0, map.width, map.height);
286
+ return isSelectionType(selection, 'cell') ? getSelectionRect(selection) : tableRect;
287
+ };
260
288
  export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, getEditorView) {
261
289
  return function (config) {
262
290
  return function (state, intl) {
@@ -272,6 +300,8 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
272
300
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
273
301
  var cellItems;
274
302
  cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(config, state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI);
303
+ var columnSettingsItems;
304
+ columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI) : [];
275
305
  var colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
276
306
 
277
307
  // Check if we need to show confirm dialog for delete button
@@ -324,7 +354,7 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
324
354
  },
325
355
  zIndex: akEditorFloatingPanelZIndex + 1,
326
356
  // Place the context menu slightly above the others
327
- items: [menu, separator(menu.hidden)].concat(_toConsumableArray(cellItems), colorPicker, [{
357
+ items: [menu, separator(menu.hidden)].concat(_toConsumableArray(cellItems), _toConsumableArray(columnSettingsItems), colorPicker, [{
328
358
  type: 'extensions-placeholder',
329
359
  separator: 'end'
330
360
  }, {
@@ -379,9 +409,52 @@ var getCellItems = function getCellItems(pluginConfig, state, view, _ref3, getEd
379
409
  }
380
410
  return [];
381
411
  };
382
- var getColorPicker = function getColorPicker(state, menu, _ref4, editorAnalyticsAPI) {
383
- var _node$attrs;
412
+ export var getDistributeConfig = function getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI) {
413
+ return function (state, dispatch, editorView) {
414
+ var selectionOrTableRect = getClosestSelectionOrTableRect(state);
415
+ if (!editorView || !selectionOrTableRect) {
416
+ return false;
417
+ }
418
+ var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, state, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
419
+ if (newResizeStateWithAnalytics) {
420
+ distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, newResizeStateWithAnalytics)(state, dispatch);
421
+ return true;
422
+ }
423
+ return false;
424
+ };
425
+ };
426
+
427
+ // this create the button group for distribute column and also fixed column width
428
+ // fixed column button should be in this function call in the future
429
+ var getColumnSettingItems = function getColumnSettingItems(editorState, editorView, _ref4, getEditorContainerWidth, editorAnalyticsAPI) {
430
+ var _newResizeStateWithAn2, _pluginState$pluginCo3;
384
431
  var formatMessage = _ref4.formatMessage;
432
+ var pluginState = getPluginState(editorState);
433
+ var selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
434
+ if (!selectionOrTableRect || !editorView) {
435
+ return [];
436
+ }
437
+ var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth);
438
+ var wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
439
+ if (pluginState !== null && pluginState !== void 0 && (_pluginState$pluginCo3 = pluginState.pluginConfig) !== null && _pluginState$pluginCo3 !== void 0 && _pluginState$pluginCo3.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
440
+ return [{
441
+ id: 'editor.table.distributeColumns',
442
+ type: 'button',
443
+ title: formatMessage(messages.distributeColumns),
444
+ icon: DistributeColumnIcon,
445
+ onClick: function onClick(state, dispatch, view) {
446
+ return getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI)(state, dispatch, view);
447
+ },
448
+ disabled: !wouldChange
449
+ }, {
450
+ type: 'separator'
451
+ }];
452
+ }
453
+ return [];
454
+ };
455
+ var getColorPicker = function getColorPicker(state, menu, _ref5, editorAnalyticsAPI) {
456
+ var _node$attrs;
457
+ var formatMessage = _ref5.formatMessage;
385
458
  var _getPluginState2 = getPluginState(state),
386
459
  targetCellPosition = _getPluginState2.targetCellPosition,
387
460
  pluginConfig = _getPluginState2.pluginConfig;
@@ -20,7 +20,7 @@ var getSelectedColumns = function getSelectedColumns(selection) {
20
20
  return [];
21
21
  };
22
22
  export var ColumnControls = function ColumnControls(_ref) {
23
- var _colWidths$map$join, _rowHeights$, _rowHeights$reduce;
23
+ var _colWidths$map$join, _rowHeights$;
24
24
  var editorView = _ref.editorView,
25
25
  tableActive = _ref.tableActive,
26
26
  tableRef = _ref.tableRef,
@@ -95,16 +95,16 @@ export var ColumnControls = function ColumnControls(_ref) {
95
95
  var colIndexes = useMemo(function () {
96
96
  return [colIndex];
97
97
  }, [colIndex]);
98
- var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
99
- return sum + cur;
100
- }, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
101
98
  var generateHandleByType = function generateHandleByType(type) {
102
- var _colWidths;
99
+ var _rowHeights$reduce, _colWidths;
103
100
  if (!hoveredCell || !(colWidths !== null && colWidths !== void 0 && colWidths.length)) {
104
101
  return null;
105
102
  }
106
103
  var isHover = type === 'hover';
107
104
  var isColumnsSelected = selectedColIndexes.length > 0;
105
+ var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
106
+ return sum + cur;
107
+ }, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
108
108
  var showCondition = isHover ? isColumnsSelected && !selectedColIndexes.includes(colIndex) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex) : selectedColIndexes.length < (colWidths === null || colWidths === void 0 ? void 0 : colWidths.length) && Number.isFinite(hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex);
109
109
  if (!showCondition) {
110
110
  return null;
@@ -112,15 +112,15 @@ export var ColumnControls = function ColumnControls(_ref) {
112
112
  var gridColumnPosition = "".concat(colIndex + 1, " / span 1");
113
113
  var selectedColumnPosition = "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length);
114
114
  var hoveredAppearance = selectedColIndexes.includes(colIndex) ? isInDanger ? 'danger' : 'selected' : 'default';
115
- var currentSelectionApprearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
116
- var istSelecting = isColumnsSelected && !isHover;
115
+ var currentSelectionAppearance = isColumnsSelected ? isInDanger ? 'danger' : 'selected' : hoveredAppearance;
116
+ var isSelecting = isColumnsSelected && !isHover;
117
117
 
118
118
  // this indexes are used to calculate the drag and drop source
119
119
  var indexes = isColumnsSelected ? isHover ? colIndexes : selectedColIndexes : colIndexes;
120
120
  return showCondition && /*#__PURE__*/React.createElement("div", {
121
121
  key: type,
122
122
  style: {
123
- gridColumn: istSelecting ? selectedColumnPosition : gridColumnPosition,
123
+ gridColumn: isSelecting ? selectedColumnPosition : gridColumnPosition,
124
124
  display: 'flex',
125
125
  justifyContent: 'center',
126
126
  alignItems: 'center',
@@ -138,7 +138,7 @@ export var ColumnControls = function ColumnControls(_ref) {
138
138
  forceDefaultHandle: isHover ? false : isColumnsSelected,
139
139
  previewWidth: (_colWidths = colWidths === null || colWidths === void 0 ? void 0 : colWidths[colIndex]) !== null && _colWidths !== void 0 ? _colWidths : tableCellMinWidth,
140
140
  previewHeight: previewHeight,
141
- appearance: istSelecting ? currentSelectionApprearance : hoveredAppearance,
141
+ appearance: isSelecting ? currentSelectionAppearance : hoveredAppearance,
142
142
  onClick: handleClick,
143
143
  onMouseOver: handleMouseOver,
144
144
  onMouseOut: handleMouseOut,
@@ -172,7 +172,7 @@ export var ColumnControls = function ColumnControls(_ref) {
172
172
  endIndex = _ref2.endIndex;
173
173
  return /*#__PURE__*/React.createElement("div", {
174
174
  style: {
175
- gridColumn: "".concat(index + 1, " / span 1")
175
+ gridColumn: "".concat(startIndex + 1, " / span 1")
176
176
  },
177
177
  "data-start-index": startIndex,
178
178
  "data-end-index": endIndex,
@@ -2,9 +2,11 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import type { Command, FloatingToolbarDropdown, FloatingToolbarHandler, FloatingToolbarItem, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import type { Rect } from '@atlaskit/editor-tables/table-map';
5
+ import { Rect } from '@atlaskit/editor-tables/table-map';
6
6
  import type { PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
7
7
  export declare const getToolbarMenuConfig: (config: ToolbarMenuConfig, state: ToolbarMenuState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarItem<Command>;
8
8
  export declare const getToolbarCellOptionsConfig: (editorState: EditorState, editorView: EditorView | undefined | null, initialSelectionRect: Rect, { formatMessage }: ToolbarMenuContext, getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarDropdown<Command>;
9
9
  export declare const getClosestSelectionRect: (state: EditorState) => Rect | undefined;
10
+ export declare const getClosestSelectionOrTableRect: (state: EditorState) => Rect | undefined;
10
11
  export declare const getToolbarConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, getEditorFeatureFlags: GetEditorFeatureFlags, getEditorView: () => EditorView | null) => (config: PluginConfig) => FloatingToolbarHandler;
12
+ export declare const getDistributeConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Command;
@@ -377,6 +377,7 @@ export interface ToolbarMenuState {
377
377
  isNumberColumnEnabled?: boolean;
378
378
  isTableCollapsed?: boolean;
379
379
  canCollapseTable?: boolean;
380
+ isDragAndDropEnabled?: boolean;
380
381
  }
381
382
  export interface ToolbarMenuContext {
382
383
  formatMessage: IntlShape['formatMessage'];
@@ -2,9 +2,11 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import type { Command, FloatingToolbarDropdown, FloatingToolbarHandler, FloatingToolbarItem, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import type { Rect } from '@atlaskit/editor-tables/table-map';
5
+ import { Rect } from '@atlaskit/editor-tables/table-map';
6
6
  import type { PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
7
7
  export declare const getToolbarMenuConfig: (config: ToolbarMenuConfig, state: ToolbarMenuState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarItem<Command>;
8
8
  export declare const getToolbarCellOptionsConfig: (editorState: EditorState, editorView: EditorView | undefined | null, initialSelectionRect: Rect, { formatMessage }: ToolbarMenuContext, getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarDropdown<Command>;
9
9
  export declare const getClosestSelectionRect: (state: EditorState) => Rect | undefined;
10
+ export declare const getClosestSelectionOrTableRect: (state: EditorState) => Rect | undefined;
10
11
  export declare const getToolbarConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, getEditorFeatureFlags: GetEditorFeatureFlags, getEditorView: () => EditorView | null) => (config: PluginConfig) => FloatingToolbarHandler;
12
+ export declare const getDistributeConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Command;
@@ -377,6 +377,7 @@ export interface ToolbarMenuState {
377
377
  isNumberColumnEnabled?: boolean;
378
378
  isTableCollapsed?: boolean;
379
379
  canCollapseTable?: boolean;
380
+ isDragAndDropEnabled?: boolean;
380
381
  }
381
382
  export interface ToolbarMenuContext {
382
383
  formatMessage: IntlShape['formatMessage'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.7.1",
3
+ "version": "5.7.2",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -140,10 +140,10 @@
140
140
  "platform.editor.a11y-table-resizing_uapcv": {
141
141
  "type": "boolean"
142
142
  },
143
- "platform.editor.a11y.table-selection_9uv33": {
143
+ "platform.editor.table.new-cell-context-menu-styling": {
144
144
  "type": "boolean"
145
145
  },
146
- "platform.editor.table.new-cell-context-menu-styling": {
146
+ "platform.editor.a11y.table-selection_9uv33": {
147
147
  "type": "boolean"
148
148
  },
149
149
  "platform.editor.menu.group-items": {
package/src/toolbar.tsx CHANGED
@@ -40,7 +40,7 @@ import { findParentDomRefOfType } from '@atlaskit/editor-prosemirror/utils';
40
40
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
41
41
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
42
42
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
43
- import type { Rect } from '@atlaskit/editor-tables/table-map';
43
+ import { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
44
44
  import {
45
45
  findCellRectClosestToPos,
46
46
  findTable,
@@ -48,7 +48,10 @@ import {
48
48
  isSelectionType,
49
49
  splitCell,
50
50
  } from '@atlaskit/editor-tables/utils';
51
+ import DistributeColumnIcon from '@atlaskit/icon/glyph/editor/layout-three-equal';
51
52
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
53
+ import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
54
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
52
55
 
53
56
  import {
54
57
  clearHoverSelection,
@@ -131,14 +134,29 @@ export const getToolbarMenuConfig = (
131
134
  },
132
135
  ];
133
136
 
134
- return {
135
- id: 'editor.table.tableOptions',
136
- type: 'dropdown',
137
- testId: 'table_options',
138
- title: formatMessage(messages.tableOptions),
139
- hidden: options.every((option) => option.hidden),
140
- options,
141
- };
137
+ if (
138
+ state.isDragAndDropEnabled &&
139
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
140
+ ) {
141
+ return {
142
+ id: 'editor.table.tableOptions',
143
+ type: 'dropdown',
144
+ testId: 'table_options',
145
+ icon: TableOptionsIcon,
146
+ title: formatMessage(messages.tableOptions),
147
+ hidden: options.every((option) => option.hidden),
148
+ options,
149
+ };
150
+ } else {
151
+ return {
152
+ id: 'editor.table.tableOptions',
153
+ type: 'dropdown',
154
+ testId: 'table_options',
155
+ title: formatMessage(messages.tableOptions),
156
+ hidden: options.every((option) => option.hidden),
157
+ options,
158
+ };
159
+ }
142
160
  };
143
161
 
144
162
  // Added these options for mobile. Mobile bridge translates this menu and
@@ -399,6 +417,22 @@ export const getClosestSelectionRect = (
399
417
  : findCellRectClosestToPos(selection.$from);
400
418
  };
401
419
 
420
+ export const getClosestSelectionOrTableRect = (
421
+ state: EditorState,
422
+ ): Rect | undefined => {
423
+ const selection = state.selection;
424
+ const tableObject = findTable(state.selection);
425
+ if (!tableObject) {
426
+ return;
427
+ }
428
+ const map = TableMap.get(tableObject.node);
429
+ const tableRect = new Rect(0, 0, map.width, map.height);
430
+
431
+ return isSelectionType(selection, 'cell')
432
+ ? getSelectionRect(selection)!
433
+ : tableRect;
434
+ };
435
+
402
436
  export const getToolbarConfig =
403
437
  (
404
438
  getEditorContainerWidth: GetEditorContainerWidth,
@@ -436,6 +470,19 @@ export const getToolbarConfig =
436
470
  getEditorContainerWidth,
437
471
  editorAnalyticsAPI,
438
472
  );
473
+
474
+ let columnSettingsItems;
475
+ columnSettingsItems =
476
+ pluginState.isDragAndDropEnabled &&
477
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
478
+ ? getColumnSettingItems(
479
+ state,
480
+ getEditorView(),
481
+ intl,
482
+ getEditorContainerWidth,
483
+ editorAnalyticsAPI,
484
+ )
485
+ : [];
439
486
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
440
487
 
441
488
  // Check if we need to show confirm dialog for delete button
@@ -502,6 +549,7 @@ export const getToolbarConfig =
502
549
  menu,
503
550
  separator(menu.hidden),
504
551
  ...cellItems,
552
+ ...columnSettingsItems,
505
553
  ...colorPicker,
506
554
  {
507
555
  type: 'extensions-placeholder',
@@ -574,6 +622,84 @@ const getCellItems = (
574
622
  return [];
575
623
  };
576
624
 
625
+ export const getDistributeConfig =
626
+ (
627
+ getEditorContainerWidth: GetEditorContainerWidth,
628
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
629
+ ): Command =>
630
+ (state, dispatch, editorView) => {
631
+ const selectionOrTableRect = getClosestSelectionOrTableRect(state);
632
+ if (!editorView || !selectionOrTableRect) {
633
+ return false;
634
+ }
635
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
636
+ selectionOrTableRect,
637
+ state,
638
+ editorView.domAtPos.bind(editorView),
639
+ getEditorContainerWidth,
640
+ );
641
+
642
+ if (newResizeStateWithAnalytics) {
643
+ distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(
644
+ INPUT_METHOD.FLOATING_TB,
645
+ newResizeStateWithAnalytics,
646
+ )(state, dispatch);
647
+ return true;
648
+ }
649
+ return false;
650
+ };
651
+
652
+ // this create the button group for distribute column and also fixed column width
653
+ // fixed column button should be in this function call in the future
654
+ const getColumnSettingItems = (
655
+ editorState: EditorState,
656
+ editorView: EditorView | undefined | null,
657
+ { formatMessage }: ToolbarMenuContext,
658
+ getEditorContainerWidth: GetEditorContainerWidth,
659
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
660
+ ): Array<FloatingToolbarItem<Command>> => {
661
+ const pluginState = getPluginState(editorState);
662
+ const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
663
+
664
+ if (!selectionOrTableRect || !editorView) {
665
+ return [];
666
+ }
667
+
668
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
669
+ selectionOrTableRect,
670
+ editorState,
671
+ editorView.domAtPos.bind(editorView),
672
+ getEditorContainerWidth,
673
+ );
674
+
675
+ const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
676
+
677
+ if (
678
+ pluginState?.pluginConfig?.allowDistributeColumns &&
679
+ pluginState.isDragAndDropEnabled
680
+ ) {
681
+ return [
682
+ {
683
+ id: 'editor.table.distributeColumns',
684
+ type: 'button',
685
+ title: formatMessage(messages.distributeColumns),
686
+ icon: DistributeColumnIcon,
687
+ onClick: (state, dispatch, view) =>
688
+ getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI)(
689
+ state,
690
+ dispatch,
691
+ view,
692
+ ),
693
+ disabled: !wouldChange,
694
+ },
695
+ {
696
+ type: 'separator',
697
+ },
698
+ ];
699
+ }
700
+ return [];
701
+ };
702
+
577
703
  const getColorPicker = (
578
704
  state: EditorState,
579
705
  menu: FloatingToolbarItem<Command>,
package/src/types.ts CHANGED
@@ -408,6 +408,7 @@ export interface ToolbarMenuState {
408
408
  isNumberColumnEnabled?: boolean;
409
409
  isTableCollapsed?: boolean;
410
410
  canCollapseTable?: boolean;
411
+ isDragAndDropEnabled?: boolean;
411
412
  }
412
413
 
413
414
  export interface ToolbarMenuContext {
@@ -154,8 +154,6 @@ export const ColumnControls = ({
154
154
  return [colIndex!];
155
155
  }, [colIndex]);
156
156
 
157
- const previewHeight = rowHeights?.reduce((sum, cur) => sum + cur, 0) ?? 0;
158
-
159
157
  const generateHandleByType = (type: HandleTypes): JSX.Element | null => {
160
158
  if (!hoveredCell || !colWidths?.length) {
161
159
  return null;
@@ -163,6 +161,7 @@ export const ColumnControls = ({
163
161
  const isHover = type === 'hover';
164
162
 
165
163
  const isColumnsSelected = selectedColIndexes.length > 0;
164
+ const previewHeight = rowHeights?.reduce((sum, cur) => sum + cur, 0) ?? 0;
166
165
 
167
166
  const showCondition = isHover
168
167
  ? isColumnsSelected &&
@@ -186,13 +185,13 @@ export const ColumnControls = ({
186
185
  : 'selected'
187
186
  : 'default';
188
187
 
189
- const currentSelectionApprearance = isColumnsSelected
188
+ const currentSelectionAppearance = isColumnsSelected
190
189
  ? isInDanger
191
190
  ? 'danger'
192
191
  : 'selected'
193
192
  : hoveredAppearance;
194
193
 
195
- const istSelecting = isColumnsSelected && !isHover;
194
+ const isSelecting = isColumnsSelected && !isHover;
196
195
 
197
196
  // this indexes are used to calculate the drag and drop source
198
197
  const indexes = isColumnsSelected
@@ -206,7 +205,7 @@ export const ColumnControls = ({
206
205
  <div
207
206
  key={type}
208
207
  style={{
209
- gridColumn: istSelecting
208
+ gridColumn: isSelecting
210
209
  ? selectedColumnPosition
211
210
  : gridColumnPosition,
212
211
  display: 'flex',
@@ -228,7 +227,7 @@ export const ColumnControls = ({
228
227
  previewWidth={colWidths?.[colIndex!] ?? tableCellMinWidth}
229
228
  previewHeight={previewHeight}
230
229
  appearance={
231
- istSelecting ? currentSelectionApprearance : hoveredAppearance
230
+ isSelecting ? currentSelectionAppearance : hoveredAppearance
232
231
  }
233
232
  onClick={handleClick}
234
233
  onMouseOver={handleMouseOver}
@@ -278,7 +277,7 @@ export const ColumnControls = ({
278
277
  columnParams.map(({ startIndex, endIndex }, index) => (
279
278
  <div
280
279
  style={{
281
- gridColumn: `${index + 1} / span 1`,
280
+ gridColumn: `${startIndex + 1} / span 1`,
282
281
  }}
283
282
  data-start-index={startIndex}
284
283
  data-end-index={endIndex}
@@ -286,16 +285,6 @@ export const ColumnControls = ({
286
285
  contentEditable={false}
287
286
  key={index}
288
287
  >
289
- {/* TODO: Disabling first column insert button https://atlassian.slack.com/archives/C05U8HRQM50/p1698363744682219?thread_ts=1698209039.104909&cid=C05U8HRQM50 */}
290
- {/* {!hasHeaderColumn && index === 0 && (
291
- <div
292
- style={{
293
- left: '0px',
294
- right: 'unset',
295
- }}
296
- className={ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT}
297
- />
298
- )} */}
299
288
  <div
300
289
  className={ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT}
301
290
  style={columnParams.length - 1 === index ? { right: '0' } : {}}
@@ -310,16 +310,6 @@ const DragControlsComponent = ({
310
310
  contentEditable={false}
311
311
  key={`insert-dot-${index}`}
312
312
  >
313
- {/* TODO: Disabling first column insert button https://atlassian.slack.com/archives/C05U8HRQM50/p1698363744682219?thread_ts=1698209039.104909&cid=C05U8HRQM50 */}
314
- {/* {!hasHeaderRow && index === 0 && (
315
- <div
316
- style={{
317
- top: '0px',
318
- left: token('space.075', '6px'),
319
- }}
320
- className={ClassName.DRAG_ROW_FLOATING_INSERT_DOT}
321
- />
322
- )} */}
323
313
  <div className={ClassName.DRAG_ROW_FLOATING_INSERT_DOT} />
324
314
  </div>
325
315
  {isDragging && (