@atlaskit/editor-plugin-table 7.16.13 → 7.16.14

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,14 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.16.14
4
+
5
+ ### Patch Changes
6
+
7
+ - [#107290](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/107290)
8
+ [`9b3d2881e8d5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9b3d2881e8d5) -
9
+ Set table width when alignment changes if not set, as layout attribute can be used to determine
10
+ width
11
+
3
12
  ## 7.16.13
4
13
 
5
14
  ### Patch Changes
@@ -8,6 +8,7 @@ exports.updateWidthToWidest = exports.updateResizeHandleDecorations = exports.tr
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
11
+ var _nodeWidth = require("@atlaskit/editor-common/node-width");
11
12
  var _utils = require("@atlaskit/editor-common/utils");
12
13
  var _state = require("@atlaskit/editor-prosemirror/state");
13
14
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
@@ -597,6 +598,13 @@ var setTableAlignment = exports.setTableAlignment = function setTableAlignment(n
597
598
  var nextTableAttrs = _objectSpread(_objectSpread({}, tableObject.node.attrs), {}, {
598
599
  layout: newAlignment
599
600
  });
601
+
602
+ // table uses old breakout values in layout attribute to determine width
603
+ // but that information is lost when alignment changes, so we need to ensure we retain that info
604
+ if (!tableObject.node.attrs.width) {
605
+ var tableWidth = (0, _nodeWidth.getTableContainerWidth)(tableObject.node);
606
+ nextTableAttrs.width = tableWidth;
607
+ }
600
608
  tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
601
609
  return tr;
602
610
  };
@@ -604,9 +612,17 @@ var setTableAlignment = exports.setTableAlignment = function setTableAlignment(n
604
612
  var setTableAlignmentWithTableContentWithPos = exports.setTableAlignmentWithTableContentWithPos = function setTableAlignmentWithTableContentWithPos(newAlignment, tableNodeWithPos) {
605
613
  return function (_ref3) {
606
614
  var tr = _ref3.tr;
607
- var nextTableAttrs = _objectSpread(_objectSpread({}, tableNodeWithPos.node.attrs), {}, {
615
+ var table = tableNodeWithPos.node;
616
+ var nextTableAttrs = _objectSpread(_objectSpread({}, table.attrs), {}, {
608
617
  layout: newAlignment
609
618
  });
619
+
620
+ // table uses old breakout values in layout attribute to determine width
621
+ // but that information is lost when alignment changes, so we need to ensure we retain that info
622
+ if (!table.attrs.width) {
623
+ var tableWidth = (0, _nodeWidth.getTableContainerWidth)(table);
624
+ nextTableAttrs.width = tableWidth;
625
+ }
610
626
  tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
611
627
  return tr;
612
628
  };
@@ -14,6 +14,7 @@ var _customSteps = require("@atlaskit/custom-steps");
14
14
  var _analytics = require("@atlaskit/editor-common/analytics");
15
15
  var _keymaps = require("@atlaskit/editor-common/keymaps");
16
16
  var _messages = _interopRequireWildcard(require("@atlaskit/editor-common/messages"));
17
+ var _nodeWidth = require("@atlaskit/editor-common/node-width");
17
18
  var _uiColor = require("@atlaskit/editor-common/ui-color");
18
19
  var _utils = require("@atlaskit/editor-common/utils");
19
20
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
@@ -661,7 +662,8 @@ var getSelectedAlignmentIcon = exports.getSelectedAlignmentIcon = function getSe
661
662
  };
662
663
  var isLayoutOptionDisabled = exports.isLayoutOptionDisabled = function isLayoutOptionDisabled(selectedNode, getEditorContainerWidth) {
663
664
  var lineLength = getEditorContainerWidth().lineLength;
664
- if (selectedNode && lineLength && selectedNode.attrs.width > lineLength) {
665
+ var tableWidth = (0, _nodeWidth.getTableContainerWidth)(selectedNode);
666
+ if (selectedNode && lineLength && tableWidth > lineLength) {
665
667
  return true;
666
668
  }
667
669
  return false;
@@ -1,4 +1,5 @@
1
1
  import isEqual from 'lodash/isEqual';
2
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
2
3
  import { closestElement, isParagraph, isTextSelection, mapSlice } from '@atlaskit/editor-common/utils';
3
4
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
5
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
@@ -561,16 +562,31 @@ export const setTableAlignment = newAlignment => ({
561
562
  ...tableObject.node.attrs,
562
563
  layout: newAlignment
563
564
  };
565
+
566
+ // table uses old breakout values in layout attribute to determine width
567
+ // but that information is lost when alignment changes, so we need to ensure we retain that info
568
+ if (!tableObject.node.attrs.width) {
569
+ const tableWidth = getTableContainerWidth(tableObject.node);
570
+ nextTableAttrs.width = tableWidth;
571
+ }
564
572
  tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
565
573
  return tr;
566
574
  };
567
575
  export const setTableAlignmentWithTableContentWithPos = (newAlignment, tableNodeWithPos) => ({
568
576
  tr
569
577
  }) => {
578
+ const table = tableNodeWithPos.node;
570
579
  const nextTableAttrs = {
571
- ...tableNodeWithPos.node.attrs,
580
+ ...table.attrs,
572
581
  layout: newAlignment
573
582
  };
583
+
584
+ // table uses old breakout values in layout attribute to determine width
585
+ // but that information is lost when alignment changes, so we need to ensure we retain that info
586
+ if (!table.attrs.width) {
587
+ const tableWidth = getTableContainerWidth(table);
588
+ nextTableAttrs.width = tableWidth;
589
+ }
574
590
  tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
575
591
  return tr;
576
592
  };
@@ -5,6 +5,7 @@ import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
5
5
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
6
  import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
7
7
  import commonMessages, { tableMessages as messages } from '@atlaskit/editor-common/messages';
8
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
8
9
  import { cellBackgroundColorPalette, DEFAULT_BORDER_COLOR } from '@atlaskit/editor-common/ui-color';
9
10
  import { closestElement, getChildrenInfo, getNodeName, isReferencedSource } from '@atlaskit/editor-common/utils';
10
11
  import { findParentDomRefOfType } from '@atlaskit/editor-prosemirror/utils';
@@ -629,7 +630,8 @@ export const getSelectedAlignmentIcon = (alignmentIcons, selectedNode) => {
629
630
  };
630
631
  export const isLayoutOptionDisabled = (selectedNode, getEditorContainerWidth) => {
631
632
  const lineLength = getEditorContainerWidth().lineLength;
632
- if (selectedNode && lineLength && selectedNode.attrs.width > lineLength) {
633
+ const tableWidth = getTableContainerWidth(selectedNode);
634
+ if (selectedNode && lineLength && tableWidth > lineLength) {
633
635
  return true;
634
636
  }
635
637
  return false;
@@ -3,6 +3,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  import isEqual from 'lodash/isEqual';
6
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
6
7
  import { closestElement, isParagraph, isTextSelection, mapSlice } from '@atlaskit/editor-common/utils';
7
8
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
8
9
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
@@ -590,6 +591,13 @@ export var setTableAlignment = function setTableAlignment(newAlignment) {
590
591
  var nextTableAttrs = _objectSpread(_objectSpread({}, tableObject.node.attrs), {}, {
591
592
  layout: newAlignment
592
593
  });
594
+
595
+ // table uses old breakout values in layout attribute to determine width
596
+ // but that information is lost when alignment changes, so we need to ensure we retain that info
597
+ if (!tableObject.node.attrs.width) {
598
+ var tableWidth = getTableContainerWidth(tableObject.node);
599
+ nextTableAttrs.width = tableWidth;
600
+ }
593
601
  tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
594
602
  return tr;
595
603
  };
@@ -597,9 +605,17 @@ export var setTableAlignment = function setTableAlignment(newAlignment) {
597
605
  export var setTableAlignmentWithTableContentWithPos = function setTableAlignmentWithTableContentWithPos(newAlignment, tableNodeWithPos) {
598
606
  return function (_ref3) {
599
607
  var tr = _ref3.tr;
600
- var nextTableAttrs = _objectSpread(_objectSpread({}, tableNodeWithPos.node.attrs), {}, {
608
+ var table = tableNodeWithPos.node;
609
+ var nextTableAttrs = _objectSpread(_objectSpread({}, table.attrs), {}, {
601
610
  layout: newAlignment
602
611
  });
612
+
613
+ // table uses old breakout values in layout attribute to determine width
614
+ // but that information is lost when alignment changes, so we need to ensure we retain that info
615
+ if (!table.attrs.width) {
616
+ var tableWidth = getTableContainerWidth(table);
617
+ nextTableAttrs.width = tableWidth;
618
+ }
603
619
  tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
604
620
  return tr;
605
621
  };
@@ -9,6 +9,7 @@ import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
9
9
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
10
10
  import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
11
11
  import commonMessages, { tableMessages as messages } from '@atlaskit/editor-common/messages';
12
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
12
13
  import { cellBackgroundColorPalette, DEFAULT_BORDER_COLOR } from '@atlaskit/editor-common/ui-color';
13
14
  import { closestElement, getChildrenInfo as _getChildrenInfo, getNodeName, isReferencedSource } from '@atlaskit/editor-common/utils';
14
15
  import { findParentDomRefOfType } from '@atlaskit/editor-prosemirror/utils';
@@ -652,7 +653,8 @@ export var getSelectedAlignmentIcon = function getSelectedAlignmentIcon(alignmen
652
653
  };
653
654
  export var isLayoutOptionDisabled = function isLayoutOptionDisabled(selectedNode, getEditorContainerWidth) {
654
655
  var lineLength = getEditorContainerWidth().lineLength;
655
- if (selectedNode && lineLength && selectedNode.attrs.width > lineLength) {
656
+ var tableWidth = getTableContainerWidth(selectedNode);
657
+ if (selectedNode && lineLength && tableWidth > lineLength) {
656
658
  return true;
657
659
  }
658
660
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.16.13",
3
+ "version": "7.16.14",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -1,6 +1,7 @@
1
1
  import isEqual from 'lodash/isEqual';
2
2
 
3
- import type { CellAttributes, TableLayout } from '@atlaskit/adf-schema';
3
+ import type { CellAttributes, TableAttributes, TableLayout } from '@atlaskit/adf-schema';
4
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
4
5
  import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
5
6
  import {
6
7
  closestElement,
@@ -735,7 +736,14 @@ export const setTableAlignment =
735
736
  const nextTableAttrs = {
736
737
  ...tableObject.node.attrs,
737
738
  layout: newAlignment,
738
- };
739
+ } as TableAttributes;
740
+
741
+ // table uses old breakout values in layout attribute to determine width
742
+ // but that information is lost when alignment changes, so we need to ensure we retain that info
743
+ if (!tableObject.node.attrs.width) {
744
+ const tableWidth = getTableContainerWidth(tableObject.node);
745
+ nextTableAttrs.width = tableWidth;
746
+ }
739
747
 
740
748
  tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
741
749
 
@@ -745,10 +753,18 @@ export const setTableAlignment =
745
753
  export const setTableAlignmentWithTableContentWithPos =
746
754
  (newAlignment: TableLayout, tableNodeWithPos: NodeWithPos): EditorCommand =>
747
755
  ({ tr }) => {
756
+ const table = tableNodeWithPos.node;
748
757
  const nextTableAttrs = {
749
- ...tableNodeWithPos.node.attrs,
758
+ ...table.attrs,
750
759
  layout: newAlignment,
751
- };
760
+ } as TableAttributes;
761
+
762
+ // table uses old breakout values in layout attribute to determine width
763
+ // but that information is lost when alignment changes, so we need to ensure we retain that info
764
+ if (!table.attrs.width) {
765
+ const tableWidth = getTableContainerWidth(table);
766
+ nextTableAttrs.width = tableWidth;
767
+ }
752
768
 
753
769
  tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta(
754
770
  'scrollIntoView',
package/src/toolbar.tsx CHANGED
@@ -6,6 +6,7 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
6
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
7
  import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
8
8
  import commonMessages, { tableMessages as messages } from '@atlaskit/editor-common/messages';
9
+ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
9
10
  import type { typeOption } from '@atlaskit/editor-common/src/types/floating-toolbar';
10
11
  import type {
11
12
  Command,
@@ -910,8 +911,9 @@ export const isLayoutOptionDisabled = (
910
911
  getEditorContainerWidth: GetEditorContainerWidth,
911
912
  ) => {
912
913
  const lineLength = getEditorContainerWidth().lineLength;
914
+ const tableWidth = getTableContainerWidth(selectedNode);
913
915
 
914
- if (selectedNode && lineLength && selectedNode.attrs.width > lineLength) {
916
+ if (selectedNode && lineLength && tableWidth > lineLength) {
915
917
  return true;
916
918
  }
917
919