@atlaskit/editor-plugin-table 7.5.14 → 7.5.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +12 -5
  3. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +4 -2
  4. package/dist/cjs/toolbar.js +58 -12
  5. package/dist/cjs/transforms/column-width.js +4 -0
  6. package/dist/cjs/ui/TableFullWidthLabel/index.js +25 -0
  7. package/dist/es2019/nodeviews/TableComponent.js +12 -5
  8. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +4 -2
  9. package/dist/es2019/toolbar.js +49 -0
  10. package/dist/es2019/transforms/column-width.js +5 -1
  11. package/dist/es2019/ui/TableFullWidthLabel/index.js +19 -0
  12. package/dist/esm/nodeviews/TableComponent.js +12 -5
  13. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +4 -2
  14. package/dist/esm/toolbar.js +58 -12
  15. package/dist/esm/transforms/column-width.js +4 -0
  16. package/dist/esm/ui/TableFullWidthLabel/index.js +18 -0
  17. package/dist/types/nodeviews/TableComponent.d.ts +2 -0
  18. package/dist/types/pm-plugins/table-resizing/utils/types.d.ts +1 -0
  19. package/dist/types/ui/TableFullWidthLabel/index.d.ts +2 -0
  20. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +2 -0
  21. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/types.d.ts +1 -0
  22. package/dist/types-ts4.5/ui/TableFullWidthLabel/index.d.ts +2 -0
  23. package/package.json +3 -3
  24. package/src/nodeviews/TableComponent.tsx +21 -7
  25. package/src/pm-plugins/table-resizing/utils/resize-state.ts +2 -0
  26. package/src/pm-plugins/table-resizing/utils/types.ts +1 -0
  27. package/src/toolbar.tsx +50 -0
  28. package/src/transforms/column-width.ts +5 -1
  29. package/src/ui/TableFullWidthLabel/index.tsx +24 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.5.16
4
+
5
+ ### Patch Changes
6
+
7
+ - [#83148](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83148) [`c7e46e32cf2d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c7e46e32cf2d) - [ux] add label in floating toolbar when table resize to widest guideline
8
+
9
+ ## 7.5.15
10
+
11
+ ### Patch Changes
12
+
13
+ - [#83567](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83567) [`755de34e0656`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/755de34e0656) - fix preserve table width copy paste and resizing to full width behaviour
14
+ - Updated dependencies
15
+
3
16
  ## 7.5.14
4
17
 
5
18
  ### Patch Changes
@@ -457,15 +457,20 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
457
457
  return;
458
458
  }
459
459
  var tableNodeWidth = (0, _nodeWidth.getTableContainerWidth)(tableNode);
460
- var shouldTableScale = tableRenderWidth < tableNodeWidth;
461
- if (force || shouldTableScale) {
460
+ var isTableResizedFullWidth = tableNodeWidth === 1800 && this.wasResizing && !isResizing;
461
+ // Needed for undo / redo
462
+ var isTableWidthChanged = tableNodeWidth !== this.tableNodeWidth;
463
+ var isTableSquashed = tableRenderWidth < tableNodeWidth;
464
+ var maybeScale = isTableSquashed || isTableWidthChanged || isTableResizedFullWidth;
465
+ if (force || maybeScale) {
462
466
  var _this$containerWidth;
463
467
  var containerWidthValue = containerWidth.width;
464
468
  var isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
465
469
  var wasTableResized = (0, _colgroup.hasTableBeenResized)(this.node);
466
- var isTableResied = (0, _colgroup.hasTableBeenResized)(tableNode);
467
- var isColumnsDistributed = wasTableResized && !isTableResied;
468
- if (force || !isResizing && (isWidthChanged || isColumnsDistributed)) {
470
+ var isTableResized = (0, _colgroup.hasTableBeenResized)(tableNode);
471
+ var isColumnsDistributed = wasTableResized && !isTableResized;
472
+ var shouldScale = isWidthChanged || isColumnsDistributed || isTableResizedFullWidth || isTableWidthChanged;
473
+ if (force || !isResizing && shouldScale) {
469
474
  var resizeState = (0, _utils4.getResizeState)({
470
475
  minWidth: _utils4.COLUMN_MIN_WIDTH,
471
476
  maxSize: tableRenderWidth,
@@ -482,6 +487,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
482
487
  });
483
488
  }
484
489
  }
490
+ this.tableNodeWidth = tableNodeWidth;
491
+ this.wasResizing = isResizing;
485
492
  this.containerWidth = containerWidth;
486
493
  }
487
494
  }, {
@@ -51,7 +51,8 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
51
51
  widths: _widths,
52
52
  maxSize: maxSize,
53
53
  tableWidth: _tableWidth,
54
- overflow: _overflow
54
+ overflow: _overflow,
55
+ isScaled: isTableScalingEnabled
55
56
  };
56
57
  }
57
58
  var shouldReinsertColgroup = !isTableScalingEnabled;
@@ -85,7 +86,8 @@ var getResizeState = exports.getResizeState = function getResizeState(_ref) {
85
86
  widths: widths,
86
87
  maxSize: maxSize,
87
88
  tableWidth: tableWidth,
88
- overflow: overflow
89
+ overflow: overflow,
90
+ isScaled: isTableScalingEnabled
89
91
  };
90
92
  };
91
93
 
@@ -31,6 +31,7 @@ var _resizeState = require("./pm-plugins/table-resizing/utils/resize-state");
31
31
  var _tableWidth = require("./pm-plugins/table-width");
32
32
  var _transforms = require("./transforms");
33
33
  var _types = require("./types");
34
+ var _TableFullWidthLabel = require("./ui/TableFullWidthLabel");
34
35
  var _utils4 = require("./utils");
35
36
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
36
37
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -307,16 +308,61 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
307
308
 
308
309
  // We don't want to show floating toolbar while resizing the table
309
310
  var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
310
- if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
311
+ var isTableScalingEnabled = pluginState.isTableScalingEnabled,
312
+ widthToWidest = pluginState.widthToWidest;
313
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
314
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
315
+ stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
311
316
  var nodeType = state.schema.nodes.table;
317
+ var getDomRef = function getDomRef(editorView) {
318
+ var element;
319
+ var domAtPos = editorView.domAtPos.bind(editorView);
320
+ var parent = (0, _utils2.findParentDomRefOfType)(nodeType, domAtPos)(state.selection);
321
+ if (parent) {
322
+ var tableRef = parent.querySelector('table') || undefined;
323
+ if (tableRef) {
324
+ element = (0, _utils.closestElement)(tableRef, ".".concat(_types.TableCssClassName.TABLE_NODE_WRAPPER)) || undefined;
325
+ }
326
+ }
327
+ return element;
328
+ };
329
+ var fullWidthLabel = {
330
+ id: 'editor.table.fullWidthLabel',
331
+ type: 'custom',
332
+ fallback: [],
333
+ render: function render() {
334
+ return (0, _react.jsx)(_TableFullWidthLabel.FullWidthDisplay, {
335
+ key: 'full-width-label'
336
+ });
337
+ }
338
+ };
339
+ return {
340
+ title: 'Table floating label',
341
+ getDomRef: getDomRef,
342
+ nodeType: nodeType,
343
+ key: 'full-width-label',
344
+ offset: [0, 18],
345
+ absoluteOffset: stickyScrollbar ? {
346
+ top: -6
347
+ } : {
348
+ top: 0
349
+ },
350
+ zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex + 1,
351
+ // Place the context menu slightly above the others
352
+ items: [fullWidthLabel],
353
+ scrollable: true
354
+ };
355
+ }
356
+ if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
357
+ var _nodeType = state.schema.nodes.table;
312
358
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
313
359
  var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
314
360
  _getPluginState2$isTa = _getPluginState2.isTableScalingEnabled,
315
- isTableScalingEnabled = _getPluginState2$isTa === void 0 ? false : _getPluginState2$isTa;
361
+ _isTableScalingEnabled = _getPluginState2$isTa === void 0 ? false : _getPluginState2$isTa;
316
362
  var cellItems;
317
- cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled);
363
+ cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, _isTableScalingEnabled);
318
364
  var columnSettingsItems;
319
- columnSettingsItems = pluginState.isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled) : [];
365
+ columnSettingsItems = pluginState.isDragAndDropEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, _isTableScalingEnabled) : [];
320
366
  var colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
321
367
 
322
368
  // Check if we need to show confirm dialog for delete button
@@ -343,10 +389,10 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
343
389
  };
344
390
  };
345
391
  }
346
- var getDomRef = function getDomRef(editorView) {
392
+ var _getDomRef = function _getDomRef(editorView) {
347
393
  var element;
348
394
  var domAtPos = editorView.domAtPos.bind(editorView);
349
- var parent = (0, _utils2.findParentDomRefOfType)(nodeType, domAtPos)(state.selection);
395
+ var parent = (0, _utils2.findParentDomRefOfType)(_nodeType, domAtPos)(state.selection);
350
396
  if (parent) {
351
397
  var tableRef = parent.querySelector('table') || undefined;
352
398
  if (tableRef) {
@@ -355,14 +401,14 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
355
401
  }
356
402
  return element;
357
403
  };
358
- var _getEditorFeatureFlag = getEditorFeatureFlags(),
359
- stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
404
+ var _getEditorFeatureFlag2 = getEditorFeatureFlags(),
405
+ _stickyScrollbar = _getEditorFeatureFlag2.stickyScrollbar;
360
406
  return {
361
407
  title: 'Table floating controls',
362
- getDomRef: getDomRef,
363
- nodeType: nodeType,
408
+ getDomRef: _getDomRef,
409
+ nodeType: _nodeType,
364
410
  offset: [0, 18],
365
- absoluteOffset: stickyScrollbar ? {
411
+ absoluteOffset: _stickyScrollbar ? {
366
412
  top: -6
367
413
  } : {
368
414
  top: 0
@@ -377,7 +423,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
377
423
  items: [{
378
424
  state: state,
379
425
  formatMessage: intl.formatMessage,
380
- nodeType: nodeType,
426
+ nodeType: _nodeType,
381
427
  onMouseEnter: (0, _commands.hoverTable)(false, true),
382
428
  onMouseLeave: (0, _commands.clearHoverSelection)(),
383
429
  onFocus: (0, _commands.hoverTable)(false, true),
@@ -33,6 +33,10 @@ var updateColumnWidths = exports.updateColumnWidths = function updateColumnWidth
33
33
  for (var columnIndex = 0; columnIndex < map.width; columnIndex++) {
34
34
  for (var rowIndex = 0; rowIndex < map.height; rowIndex++) {
35
35
  var width = resizeState.cols[columnIndex].width;
36
+ if (resizeState.isScaled) {
37
+ // Ensure that the width is an integer if the table has been scaled
38
+ width = Math.floor(width);
39
+ }
36
40
  var mapIndex = rowIndex * map.width + columnIndex;
37
41
  var cellPos = map.map[mapIndex];
38
42
  var attrs = updatedCellsAttrs[cellPos] || _objectSpread({}, table.nodeAt(cellPos).attrs);
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FullWidthDisplay = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _messages = require("@atlaskit/editor-common/messages");
11
+ var _primitives = require("@atlaskit/primitives");
12
+ var tableFullWidthLabelStyles = (0, _primitives.xcss)({
13
+ minWidth: '120px',
14
+ height: "var(--ds-space-300, 24px)",
15
+ display: 'flex',
16
+ justifyContent: 'center',
17
+ alignItems: 'center'
18
+ });
19
+ var FullWidthDisplay = exports.FullWidthDisplay = function FullWidthDisplay() {
20
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
21
+ formatMessage = _useIntl.formatMessage;
22
+ return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
23
+ xcss: tableFullWidthLabelStyles
24
+ }, /*#__PURE__*/_react.default.createElement(_primitives.Inline, null, formatMessage(_messages.tableMessages.fullWidthLabel)));
25
+ };
@@ -439,17 +439,22 @@ class TableComponent extends React.Component {
439
439
  return;
440
440
  }
441
441
  const tableNodeWidth = getTableContainerWidth(tableNode);
442
- const shouldTableScale = tableRenderWidth < tableNodeWidth;
443
- if (force || shouldTableScale) {
442
+ const isTableResizedFullWidth = tableNodeWidth === 1800 && this.wasResizing && !isResizing;
443
+ // Needed for undo / redo
444
+ const isTableWidthChanged = tableNodeWidth !== this.tableNodeWidth;
445
+ const isTableSquashed = tableRenderWidth < tableNodeWidth;
446
+ const maybeScale = isTableSquashed || isTableWidthChanged || isTableResizedFullWidth;
447
+ if (force || maybeScale) {
444
448
  var _this$containerWidth;
445
449
  const {
446
450
  width: containerWidthValue
447
451
  } = containerWidth;
448
452
  const isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
449
453
  const wasTableResized = hasTableBeenResized(this.node);
450
- const isTableResied = hasTableBeenResized(tableNode);
451
- const isColumnsDistributed = wasTableResized && !isTableResied;
452
- if (force || !isResizing && (isWidthChanged || isColumnsDistributed)) {
454
+ const isTableResized = hasTableBeenResized(tableNode);
455
+ const isColumnsDistributed = wasTableResized && !isTableResized;
456
+ const shouldScale = isWidthChanged || isColumnsDistributed || isTableResizedFullWidth || isTableWidthChanged;
457
+ if (force || !isResizing && shouldScale) {
453
458
  const resizeState = getResizeState({
454
459
  minWidth: COLUMN_MIN_WIDTH,
455
460
  maxSize: tableRenderWidth,
@@ -466,6 +471,8 @@ class TableComponent extends React.Component {
466
471
  });
467
472
  }
468
473
  }
474
+ this.tableNodeWidth = tableNodeWidth;
475
+ this.wasResizing = isResizing;
469
476
  this.containerWidth = containerWidth;
470
477
  }
471
478
  componentDidUpdate(_, prevState) {
@@ -35,7 +35,8 @@ export const getResizeState = ({
35
35
  widths,
36
36
  maxSize,
37
37
  tableWidth,
38
- overflow
38
+ overflow,
39
+ isScaled: isTableScalingEnabled
39
40
  };
40
41
  }
41
42
  const shouldReinsertColgroup = !isTableScalingEnabled;
@@ -65,7 +66,8 @@ export const getResizeState = ({
65
66
  widths,
66
67
  maxSize,
67
68
  tableWidth,
68
- overflow
69
+ overflow,
70
+ isScaled: isTableScalingEnabled
69
71
  };
70
72
  };
71
73
 
@@ -23,6 +23,7 @@ import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizin
23
23
  import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
24
24
  import { canMergeCells } from './transforms';
25
25
  import { TableCssClassName } from './types';
26
+ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
26
27
  import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes } from './utils';
27
28
  export const getToolbarMenuConfig = (config, state, {
28
29
  formatMessage
@@ -293,6 +294,54 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
293
294
 
294
295
  // We don't want to show floating toolbar while resizing the table
295
296
  const isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
297
+ const {
298
+ isTableScalingEnabled,
299
+ widthToWidest
300
+ } = pluginState;
301
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
302
+ const {
303
+ stickyScrollbar
304
+ } = getEditorFeatureFlags();
305
+ const nodeType = state.schema.nodes.table;
306
+ const getDomRef = editorView => {
307
+ let element;
308
+ const domAtPos = editorView.domAtPos.bind(editorView);
309
+ const parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
310
+ if (parent) {
311
+ const tableRef = parent.querySelector('table') || undefined;
312
+ if (tableRef) {
313
+ element = closestElement(tableRef, `.${TableCssClassName.TABLE_NODE_WRAPPER}`) || undefined;
314
+ }
315
+ }
316
+ return element;
317
+ };
318
+ const fullWidthLabel = {
319
+ id: 'editor.table.fullWidthLabel',
320
+ type: 'custom',
321
+ fallback: [],
322
+ render: () => {
323
+ return jsx(FullWidthDisplay, {
324
+ key: 'full-width-label'
325
+ });
326
+ }
327
+ };
328
+ return {
329
+ title: 'Table floating label',
330
+ getDomRef,
331
+ nodeType,
332
+ key: 'full-width-label',
333
+ offset: [0, 18],
334
+ absoluteOffset: stickyScrollbar ? {
335
+ top: -6
336
+ } : {
337
+ top: 0
338
+ },
339
+ zIndex: akEditorFloatingPanelZIndex + 1,
340
+ // Place the context menu slightly above the others
341
+ items: [fullWidthLabel],
342
+ scrollable: true
343
+ };
344
+ }
296
345
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
297
346
  const nodeType = state.schema.nodes.table;
298
347
  const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
@@ -22,9 +22,13 @@ export const updateColumnWidths = (resizeState, table, start) => tr => {
22
22
  // calculating new attributes for each cell
23
23
  for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
24
24
  for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
25
- const {
25
+ let {
26
26
  width
27
27
  } = resizeState.cols[columnIndex];
28
+ if (resizeState.isScaled) {
29
+ // Ensure that the width is an integer if the table has been scaled
30
+ width = Math.floor(width);
31
+ }
28
32
  const mapIndex = rowIndex * map.width + columnIndex;
29
33
  const cellPos = map.map[mapIndex];
30
34
  const attrs = updatedCellsAttrs[cellPos] || {
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
+ import { Box, Inline, xcss } from '@atlaskit/primitives';
5
+ const tableFullWidthLabelStyles = xcss({
6
+ minWidth: '120px',
7
+ height: "var(--ds-space-300, 24px)",
8
+ display: 'flex',
9
+ justifyContent: 'center',
10
+ alignItems: 'center'
11
+ });
12
+ export const FullWidthDisplay = () => {
13
+ const {
14
+ formatMessage
15
+ } = useIntl();
16
+ return /*#__PURE__*/React.createElement(Box, {
17
+ xcss: tableFullWidthLabelStyles
18
+ }, /*#__PURE__*/React.createElement(Inline, null, formatMessage(messages.fullWidthLabel)));
19
+ };
@@ -450,15 +450,20 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
450
450
  return;
451
451
  }
452
452
  var tableNodeWidth = getTableContainerWidth(tableNode);
453
- var shouldTableScale = tableRenderWidth < tableNodeWidth;
454
- if (force || shouldTableScale) {
453
+ var isTableResizedFullWidth = tableNodeWidth === 1800 && this.wasResizing && !isResizing;
454
+ // Needed for undo / redo
455
+ var isTableWidthChanged = tableNodeWidth !== this.tableNodeWidth;
456
+ var isTableSquashed = tableRenderWidth < tableNodeWidth;
457
+ var maybeScale = isTableSquashed || isTableWidthChanged || isTableResizedFullWidth;
458
+ if (force || maybeScale) {
455
459
  var _this$containerWidth;
456
460
  var containerWidthValue = containerWidth.width;
457
461
  var isWidthChanged = ((_this$containerWidth = this.containerWidth) === null || _this$containerWidth === void 0 ? void 0 : _this$containerWidth.width) !== containerWidthValue;
458
462
  var wasTableResized = hasTableBeenResized(this.node);
459
- var isTableResied = hasTableBeenResized(tableNode);
460
- var isColumnsDistributed = wasTableResized && !isTableResied;
461
- if (force || !isResizing && (isWidthChanged || isColumnsDistributed)) {
463
+ var isTableResized = hasTableBeenResized(tableNode);
464
+ var isColumnsDistributed = wasTableResized && !isTableResized;
465
+ var shouldScale = isWidthChanged || isColumnsDistributed || isTableResizedFullWidth || isTableWidthChanged;
466
+ if (force || !isResizing && shouldScale) {
462
467
  var resizeState = getResizeState({
463
468
  minWidth: COLUMN_MIN_WIDTH,
464
469
  maxSize: tableRenderWidth,
@@ -475,6 +480,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
475
480
  });
476
481
  }
477
482
  }
483
+ this.tableNodeWidth = tableNodeWidth;
484
+ this.wasResizing = isResizing;
478
485
  this.containerWidth = containerWidth;
479
486
  }
480
487
  }, {
@@ -44,7 +44,8 @@ export var getResizeState = function getResizeState(_ref) {
44
44
  widths: _widths,
45
45
  maxSize: maxSize,
46
46
  tableWidth: _tableWidth,
47
- overflow: _overflow
47
+ overflow: _overflow,
48
+ isScaled: isTableScalingEnabled
48
49
  };
49
50
  }
50
51
  var shouldReinsertColgroup = !isTableScalingEnabled;
@@ -78,7 +79,8 @@ export var getResizeState = function getResizeState(_ref) {
78
79
  widths: widths,
79
80
  maxSize: maxSize,
80
81
  tableWidth: tableWidth,
81
- overflow: overflow
82
+ overflow: overflow,
83
+ isScaled: isTableScalingEnabled
82
84
  };
83
85
  };
84
86
 
@@ -24,6 +24,7 @@ import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizin
24
24
  import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
25
25
  import { canMergeCells } from './transforms';
26
26
  import { TableCssClassName } from './types';
27
+ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
27
28
  import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes } from './utils';
28
29
  export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
29
30
  var formatMessage = _ref.formatMessage;
@@ -296,16 +297,61 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
296
297
 
297
298
  // We don't want to show floating toolbar while resizing the table
298
299
  var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
299
- if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
300
+ var isTableScalingEnabled = pluginState.isTableScalingEnabled,
301
+ widthToWidest = pluginState.widthToWidest;
302
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
303
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
304
+ stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
300
305
  var nodeType = state.schema.nodes.table;
306
+ var getDomRef = function getDomRef(editorView) {
307
+ var element;
308
+ var domAtPos = editorView.domAtPos.bind(editorView);
309
+ var parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
310
+ if (parent) {
311
+ var tableRef = parent.querySelector('table') || undefined;
312
+ if (tableRef) {
313
+ element = closestElement(tableRef, ".".concat(TableCssClassName.TABLE_NODE_WRAPPER)) || undefined;
314
+ }
315
+ }
316
+ return element;
317
+ };
318
+ var fullWidthLabel = {
319
+ id: 'editor.table.fullWidthLabel',
320
+ type: 'custom',
321
+ fallback: [],
322
+ render: function render() {
323
+ return jsx(FullWidthDisplay, {
324
+ key: 'full-width-label'
325
+ });
326
+ }
327
+ };
328
+ return {
329
+ title: 'Table floating label',
330
+ getDomRef: getDomRef,
331
+ nodeType: nodeType,
332
+ key: 'full-width-label',
333
+ offset: [0, 18],
334
+ absoluteOffset: stickyScrollbar ? {
335
+ top: -6
336
+ } : {
337
+ top: 0
338
+ },
339
+ zIndex: akEditorFloatingPanelZIndex + 1,
340
+ // Place the context menu slightly above the others
341
+ items: [fullWidthLabel],
342
+ scrollable: true
343
+ };
344
+ }
345
+ if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
346
+ var _nodeType = state.schema.nodes.table;
301
347
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
302
348
  var _getPluginState2 = getPluginState(state),
303
349
  _getPluginState2$isTa = _getPluginState2.isTableScalingEnabled,
304
- isTableScalingEnabled = _getPluginState2$isTa === void 0 ? false : _getPluginState2$isTa;
350
+ _isTableScalingEnabled = _getPluginState2$isTa === void 0 ? false : _getPluginState2$isTa;
305
351
  var cellItems;
306
- cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled);
352
+ cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, _isTableScalingEnabled);
307
353
  var columnSettingsItems;
308
- columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled) : [];
354
+ columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, _isTableScalingEnabled) : [];
309
355
  var colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
310
356
 
311
357
  // Check if we need to show confirm dialog for delete button
@@ -332,10 +378,10 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
332
378
  };
333
379
  };
334
380
  }
335
- var getDomRef = function getDomRef(editorView) {
381
+ var _getDomRef = function _getDomRef(editorView) {
336
382
  var element;
337
383
  var domAtPos = editorView.domAtPos.bind(editorView);
338
- var parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
384
+ var parent = findParentDomRefOfType(_nodeType, domAtPos)(state.selection);
339
385
  if (parent) {
340
386
  var tableRef = parent.querySelector('table') || undefined;
341
387
  if (tableRef) {
@@ -344,14 +390,14 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
344
390
  }
345
391
  return element;
346
392
  };
347
- var _getEditorFeatureFlag = getEditorFeatureFlags(),
348
- stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
393
+ var _getEditorFeatureFlag2 = getEditorFeatureFlags(),
394
+ _stickyScrollbar = _getEditorFeatureFlag2.stickyScrollbar;
349
395
  return {
350
396
  title: 'Table floating controls',
351
- getDomRef: getDomRef,
352
- nodeType: nodeType,
397
+ getDomRef: _getDomRef,
398
+ nodeType: _nodeType,
353
399
  offset: [0, 18],
354
- absoluteOffset: stickyScrollbar ? {
400
+ absoluteOffset: _stickyScrollbar ? {
355
401
  top: -6
356
402
  } : {
357
403
  top: 0
@@ -366,7 +412,7 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
366
412
  items: [{
367
413
  state: state,
368
414
  formatMessage: intl.formatMessage,
369
- nodeType: nodeType,
415
+ nodeType: _nodeType,
370
416
  onMouseEnter: hoverTable(false, true),
371
417
  onMouseLeave: clearHoverSelection(),
372
418
  onFocus: hoverTable(false, true),
@@ -27,6 +27,10 @@ export var updateColumnWidths = function updateColumnWidths(resizeState, table,
27
27
  for (var columnIndex = 0; columnIndex < map.width; columnIndex++) {
28
28
  for (var rowIndex = 0; rowIndex < map.height; rowIndex++) {
29
29
  var width = resizeState.cols[columnIndex].width;
30
+ if (resizeState.isScaled) {
31
+ // Ensure that the width is an integer if the table has been scaled
32
+ width = Math.floor(width);
33
+ }
30
34
  var mapIndex = rowIndex * map.width + columnIndex;
31
35
  var cellPos = map.map[mapIndex];
32
36
  var attrs = updatedCellsAttrs[cellPos] || _objectSpread({}, table.nodeAt(cellPos).attrs);
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
+ import { Box, Inline, xcss } from '@atlaskit/primitives';
5
+ var tableFullWidthLabelStyles = xcss({
6
+ minWidth: '120px',
7
+ height: "var(--ds-space-300, 24px)",
8
+ display: 'flex',
9
+ justifyContent: 'center',
10
+ alignItems: 'center'
11
+ });
12
+ export var FullWidthDisplay = function FullWidthDisplay() {
13
+ var _useIntl = useIntl(),
14
+ formatMessage = _useIntl.formatMessage;
15
+ return /*#__PURE__*/React.createElement(Box, {
16
+ xcss: tableFullWidthLabelStyles
17
+ }, /*#__PURE__*/React.createElement(Inline, null, formatMessage(messages.fullWidthLabel)));
18
+ };
@@ -47,6 +47,8 @@ declare class TableComponent extends React.Component<ComponentProps, TableState>
47
47
  private table?;
48
48
  private node;
49
49
  private containerWidth?;
50
+ private wasResizing?;
51
+ private tableNodeWidth?;
50
52
  private layoutSize?;
51
53
  private overflowShadowsObserver?;
52
54
  private stickyScrollbar?;
@@ -6,6 +6,7 @@ export interface ResizeState {
6
6
  maxSize: number;
7
7
  overflow: boolean;
8
8
  tableWidth: number;
9
+ isScaled?: boolean;
9
10
  }
10
11
  export interface ResizeStateWithAnalytics {
11
12
  resizeState: ResizeState;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const FullWidthDisplay: () => JSX.Element;
@@ -47,6 +47,8 @@ declare class TableComponent extends React.Component<ComponentProps, TableState>
47
47
  private table?;
48
48
  private node;
49
49
  private containerWidth?;
50
+ private wasResizing?;
51
+ private tableNodeWidth?;
50
52
  private layoutSize?;
51
53
  private overflowShadowsObserver?;
52
54
  private stickyScrollbar?;
@@ -6,6 +6,7 @@ export interface ResizeState {
6
6
  maxSize: number;
7
7
  overflow: boolean;
8
8
  tableWidth: number;
9
+ isScaled?: boolean;
9
10
  }
10
11
  export interface ResizeStateWithAnalytics {
11
12
  resizeState: ResizeState;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const FullWidthDisplay: () => JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.5.14",
3
+ "version": "7.5.16",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^35.7.0",
32
32
  "@atlaskit/custom-steps": "^0.0.16",
33
- "@atlaskit/editor-common": "^78.18.0",
33
+ "@atlaskit/editor-common": "^78.19.0",
34
34
  "@atlaskit/editor-palette": "1.5.3",
35
35
  "@atlaskit/editor-plugin-analytics": "^1.0.0",
36
36
  "@atlaskit/editor-plugin-content-insertion": "^1.0.0",
@@ -43,7 +43,7 @@
43
43
  "@atlaskit/icon": "^22.1.0",
44
44
  "@atlaskit/menu": "^2.1.5",
45
45
  "@atlaskit/platform-feature-flags": "^0.2.1",
46
- "@atlaskit/pragmatic-drag-and-drop": "^1.0.0",
46
+ "@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
47
47
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.0.0",
48
48
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
49
49
  "@atlaskit/primitives": "^5.1.0",
@@ -140,6 +140,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
140
140
  private table?: HTMLTableElement | null;
141
141
  private node: PmNode;
142
142
  private containerWidth?: EditorContainerWidth;
143
+ private wasResizing?: boolean;
144
+ private tableNodeWidth?: number;
143
145
  private layoutSize?: number;
144
146
  private overflowShadowsObserver?: OverflowShadowsObserver;
145
147
  private stickyScrollbar?: TableStickyScrollbar;
@@ -338,16 +340,26 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
338
340
  }
339
341
 
340
342
  const tableNodeWidth = getTableContainerWidth(tableNode);
341
- const shouldTableScale = tableRenderWidth < tableNodeWidth;
342
- if (force || shouldTableScale) {
343
+ const isTableResizedFullWidth =
344
+ tableNodeWidth === 1800 && this.wasResizing && !isResizing;
345
+ // Needed for undo / redo
346
+ const isTableWidthChanged = tableNodeWidth !== this.tableNodeWidth;
347
+ const isTableSquashed = tableRenderWidth < tableNodeWidth;
348
+
349
+ const maybeScale =
350
+ isTableSquashed || isTableWidthChanged || isTableResizedFullWidth;
351
+ if (force || maybeScale) {
343
352
  const { width: containerWidthValue } = containerWidth;
344
353
  const isWidthChanged = this.containerWidth?.width !== containerWidthValue;
345
-
346
354
  const wasTableResized = hasTableBeenResized(this.node);
347
- const isTableResied = hasTableBeenResized(tableNode);
348
- const isColumnsDistributed = wasTableResized && !isTableResied;
349
-
350
- if (force || (!isResizing && (isWidthChanged || isColumnsDistributed))) {
355
+ const isTableResized = hasTableBeenResized(tableNode);
356
+ const isColumnsDistributed = wasTableResized && !isTableResized;
357
+ const shouldScale =
358
+ isWidthChanged ||
359
+ isColumnsDistributed ||
360
+ isTableResizedFullWidth ||
361
+ isTableWidthChanged;
362
+ if (force || (!isResizing && shouldScale)) {
351
363
  const resizeState = getResizeState({
352
364
  minWidth: COLUMN_MIN_WIDTH,
353
365
  maxSize: tableRenderWidth,
@@ -364,6 +376,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
364
376
  });
365
377
  }
366
378
  }
379
+ this.tableNodeWidth = tableNodeWidth;
380
+ this.wasResizing = isResizing;
367
381
  this.containerWidth = containerWidth;
368
382
  }
369
383
 
@@ -63,6 +63,7 @@ export const getResizeState = ({
63
63
  maxSize,
64
64
  tableWidth,
65
65
  overflow,
66
+ isScaled: isTableScalingEnabled,
66
67
  };
67
68
  }
68
69
 
@@ -101,6 +102,7 @@ export const getResizeState = ({
101
102
  maxSize,
102
103
  tableWidth,
103
104
  overflow,
105
+ isScaled: isTableScalingEnabled,
104
106
  };
105
107
  };
106
108
 
@@ -8,6 +8,7 @@ export interface ResizeState {
8
8
  maxSize: number;
9
9
  overflow: boolean;
10
10
  tableWidth: number;
11
+ isScaled?: boolean;
11
12
  }
12
13
  export interface ResizeStateWithAnalytics {
13
14
  resizeState: ResizeState;
package/src/toolbar.tsx CHANGED
@@ -90,6 +90,7 @@ import type {
90
90
  ToolbarMenuState,
91
91
  } from './types';
92
92
  import { TableCssClassName } from './types';
93
+ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
93
94
  import {
94
95
  getMergedCellsPositions,
95
96
  getSelectedColumnIndexes,
@@ -452,6 +453,55 @@ export const getToolbarConfig =
452
453
  // We don't want to show floating toolbar while resizing the table
453
454
  const isWidthResizing = tableWidthState?.resizing;
454
455
 
456
+ const { isTableScalingEnabled, widthToWidest } = pluginState;
457
+
458
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
459
+ const { stickyScrollbar } = getEditorFeatureFlags();
460
+
461
+ const nodeType = state.schema.nodes.table;
462
+ const getDomRef = (editorView: EditorView) => {
463
+ let element: HTMLElement | undefined;
464
+ const domAtPos = editorView.domAtPos.bind(editorView);
465
+ const parent = findParentDomRefOfType(
466
+ nodeType,
467
+ domAtPos,
468
+ )(state.selection);
469
+ if (parent) {
470
+ const tableRef =
471
+ (parent as HTMLElement).querySelector<HTMLTableElement>('table') ||
472
+ undefined;
473
+ if (tableRef) {
474
+ element =
475
+ closestElement(
476
+ tableRef,
477
+ `.${TableCssClassName.TABLE_NODE_WRAPPER}`,
478
+ ) || undefined;
479
+ }
480
+ }
481
+ return element;
482
+ };
483
+ const fullWidthLabel = {
484
+ id: 'editor.table.fullWidthLabel',
485
+ type: 'custom',
486
+ fallback: [],
487
+ render: () => {
488
+ return <FullWidthDisplay key={'full-width-label'} />;
489
+ },
490
+ } as FloatingToolbarItem<Command>;
491
+
492
+ return {
493
+ title: 'Table floating label',
494
+ getDomRef,
495
+ nodeType,
496
+ key: 'full-width-label',
497
+ offset: [0, 18],
498
+ absoluteOffset: stickyScrollbar ? { top: -6 } : { top: 0 },
499
+ zIndex: akEditorFloatingPanelZIndex + 1, // Place the context menu slightly above the others
500
+ items: [fullWidthLabel],
501
+ scrollable: true,
502
+ };
503
+ }
504
+
455
505
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
456
506
  const nodeType = state.schema.nodes.table;
457
507
  const menu = getToolbarMenuConfig(
@@ -35,7 +35,11 @@ export const updateColumnWidths =
35
35
  // calculating new attributes for each cell
36
36
  for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
37
37
  for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
38
- const { width } = resizeState.cols[columnIndex];
38
+ let { width } = resizeState.cols[columnIndex];
39
+ if (resizeState.isScaled) {
40
+ // Ensure that the width is an integer if the table has been scaled
41
+ width = Math.floor(width);
42
+ }
39
43
  const mapIndex = rowIndex * map.width + columnIndex;
40
44
  const cellPos = map.map[mapIndex];
41
45
  const attrs = updatedCellsAttrs[cellPos] || {
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+
3
+ import { useIntl } from 'react-intl-next';
4
+
5
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { Box, Inline, xcss } from '@atlaskit/primitives';
7
+ import { token } from '@atlaskit/tokens';
8
+
9
+ const tableFullWidthLabelStyles = xcss({
10
+ minWidth: '120px',
11
+ height: token('space.300', '24px'),
12
+ display: 'flex',
13
+ justifyContent: 'center',
14
+ alignItems: 'center',
15
+ });
16
+
17
+ export const FullWidthDisplay = () => {
18
+ const { formatMessage } = useIntl();
19
+ return (
20
+ <Box xcss={tableFullWidthLabelStyles}>
21
+ <Inline>{formatMessage(messages.fullWidthLabel)}</Inline>
22
+ </Box>
23
+ );
24
+ };