@atlaskit/editor-plugin-table 7.28.7 → 7.28.9

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 (38) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +4 -9
  3. package/dist/cjs/plugin.js +1 -1
  4. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +9 -1
  5. package/dist/cjs/pm-plugins/table-resizing/utils/index.js +6 -0
  6. package/dist/cjs/pm-plugins/view-mode-sort/index.js +9 -8
  7. package/dist/cjs/toDOM.js +3 -2
  8. package/dist/cjs/ui/icons/SortingIconWrapper.js +18 -0
  9. package/dist/es2019/nodeviews/TableComponent.js +4 -10
  10. package/dist/es2019/plugin.js +1 -1
  11. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +8 -0
  12. package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
  13. package/dist/es2019/pm-plugins/view-mode-sort/index.js +9 -8
  14. package/dist/es2019/toDOM.js +4 -3
  15. package/dist/es2019/ui/icons/SortingIconWrapper.js +12 -0
  16. package/dist/esm/nodeviews/TableComponent.js +4 -9
  17. package/dist/esm/plugin.js +1 -1
  18. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +8 -0
  19. package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
  20. package/dist/esm/pm-plugins/view-mode-sort/index.js +9 -8
  21. package/dist/esm/toDOM.js +4 -3
  22. package/dist/esm/ui/icons/SortingIconWrapper.js +11 -0
  23. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -0
  24. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  25. package/dist/types/pm-plugins/view-mode-sort/index.d.ts +1 -1
  26. package/dist/types/ui/icons/SortingIconWrapper.d.ts +10 -0
  27. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -0
  28. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  29. package/dist/types-ts4.5/pm-plugins/view-mode-sort/index.d.ts +1 -1
  30. package/dist/types-ts4.5/ui/icons/SortingIconWrapper.d.ts +10 -0
  31. package/package.json +4 -4
  32. package/src/nodeviews/TableComponent.tsx +1 -5
  33. package/src/plugin.tsx +1 -1
  34. package/src/pm-plugins/table-resizing/utils/colgroup.ts +9 -0
  35. package/src/pm-plugins/table-resizing/utils/index.ts +1 -0
  36. package/src/pm-plugins/view-mode-sort/index.ts +6 -8
  37. package/src/toDOM.ts +5 -3
  38. package/src/ui/icons/SortingIconWrapper.tsx +20 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 7.28.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#150125](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/150125)
8
+ [`c9d8f549c024a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c9d8f549c024a) -
9
+ [ux] ED-24539 Fix live view toggle and column sorting in live view pages
10
+
11
+ ## 7.28.8
12
+
13
+ ### Patch Changes
14
+
15
+ - [#150410](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/150410)
16
+ [`aabd4874bd3a0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/aabd4874bd3a0) -
17
+ set correct min-width value in table lazy load view
18
+
3
19
  ## 7.28.7
4
20
 
5
21
  ### Patch Changes
@@ -358,7 +358,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
358
358
  (0, _createClass2.default)(TableComponent, [{
359
359
  key: "componentDidMount",
360
360
  value: function componentDidMount() {
361
- var _this$props$pluginInj, _this$table2, _this$table3;
361
+ var _this$table, _this$table2, _this$table3;
362
362
  var _this$props7 = this.props,
363
363
  allowColumnResizing = _this$props7.allowColumnResizing,
364
364
  eventDispatcher = _this$props7.eventDispatcher,
@@ -367,12 +367,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
367
367
  getNode = _this$props7.getNode,
368
368
  getEditorFeatureFlags = _this$props7.getEditorFeatureFlags,
369
369
  isTableScalingEnabled = _this$props7.isTableScalingEnabled;
370
- var _ref = ((_this$props$pluginInj = this.props.pluginInjectionApi) === null || _this$props$pluginInj === void 0 || (_this$props$pluginInj = _this$props$pluginInj.editorViewMode) === null || _this$props$pluginInj === void 0 ? void 0 : _this$props$pluginInj.sharedState.currentState()) || {},
371
- mode = _ref.mode;
372
- if (mode === 'view') {
373
- var _this$table;
374
- this === null || this === void 0 || (_this$table = this.table) === null || _this$table === void 0 || _this$table.addEventListener('mouseenter', this.handleMouseEnter);
375
- }
370
+ this === null || this === void 0 || (_this$table = this.table) === null || _this$table === void 0 || _this$table.addEventListener('mouseenter', this.handleMouseEnter);
376
371
  this === null || this === void 0 || (_this$table2 = this.table) === null || _this$table2 === void 0 || _this$table2.addEventListener('mouseout', this.handleMouseOut);
377
372
  this === null || this === void 0 || (_this$table3 = this.table) === null || _this$table3 === void 0 || _this$table3.addEventListener('mouseover', this.handleMouseOver);
378
373
  var _getEditorFeatureFlag = getEditorFeatureFlags(),
@@ -647,8 +642,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
647
642
  var isNoOfColumnsChanged = (0, _utils5.tablesHaveDifferentNoOfColumns)(currentTable, previousTable);
648
643
  var isNoOfRowsChanged = (0, _utils5.tablesHaveDifferentNoOfRows)(currentTable, previousTable);
649
644
  if (isNoOfColumnsChanged || isNoOfRowsChanged) {
650
- var _this$props$pluginInj2;
651
- (_this$props$pluginInj2 = this.props.pluginInjectionApi) === null || _this$props$pluginInj2 === void 0 || (_this$props$pluginInj2 = _this$props$pluginInj2.accessibilityUtils) === null || _this$props$pluginInj2 === void 0 || _this$props$pluginInj2.actions.ariaNotify((0, _utils5.getAssistiveMessage)(previousTable, currentTable, this.props.intl), {
645
+ var _this$props$pluginInj;
646
+ (_this$props$pluginInj = this.props.pluginInjectionApi) === null || _this$props$pluginInj === void 0 || (_this$props$pluginInj = _this$props$pluginInj.accessibilityUtils) === null || _this$props$pluginInj === void 0 || _this$props$pluginInj.actions.ariaNotify((0, _utils5.getAssistiveMessage)(previousTable, currentTable, this.props.intl), {
652
647
  priority: 'important'
653
648
  });
654
649
  }
@@ -275,7 +275,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
275
275
  }, {
276
276
  name: 'tableViewModeSort',
277
277
  plugin: function plugin() {
278
- return api !== null && api !== void 0 && api.editorViewMode ? (0, _viewModeSort.createPlugin)(api.editorViewMode) : undefined;
278
+ return api !== null && api !== void 0 && api.editorViewMode ? (0, _viewModeSort.createPlugin)(api) : undefined;
279
279
  }
280
280
  }, {
281
281
  name: 'tableLocalId',
@@ -4,12 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.isMinCellWidthTable = exports.insertColgroupFromNode = exports.hasTableColumnBeenResized = exports.hasTableBeenResized = exports.getColgroupChildrenLength = exports.getColWidthFix = exports.generateColgroup = void 0;
7
+ exports.isMinCellWidthTable = exports.insertColgroupFromNode = exports.hasTableColumnBeenResized = exports.hasTableBeenResized = exports.getResizerMinWidth = exports.getColgroupChildrenLength = exports.getColWidthFix = exports.generateColgroup = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _styles = require("@atlaskit/editor-common/styles");
10
10
  var _utils = require("@atlaskit/editor-common/utils");
11
11
  var _model = require("@atlaskit/editor-prosemirror/model");
12
12
  var _tableMap = require("@atlaskit/editor-tables/table-map");
13
+ var _consts = require("./consts");
13
14
  var _misc = require("./misc");
14
15
  /**
15
16
  * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
@@ -109,4 +110,11 @@ function renderColgroupFromNode(table, maybeTableRef, shouldUseIncreasedScalingP
109
110
  var getColgroupChildrenLength = exports.getColgroupChildrenLength = function getColgroupChildrenLength(table) {
110
111
  var map = _tableMap.TableMap.get(table);
111
112
  return map.width;
113
+ };
114
+ var getResizerMinWidth = exports.getResizerMinWidth = function getResizerMinWidth(node) {
115
+ var currentColumnCount = getColgroupChildrenLength(node);
116
+ var minColumnWidth = Math.min(3, currentColumnCount) * _consts.COLUMN_MIN_WIDTH;
117
+ // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
118
+ // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
119
+ return minColumnWidth + 1;
112
120
  };
@@ -81,6 +81,12 @@ Object.defineProperty(exports, "getResizeState", {
81
81
  return _resizeState.getResizeState;
82
82
  }
83
83
  });
84
+ Object.defineProperty(exports, "getResizerMinWidth", {
85
+ enumerable: true,
86
+ get: function get() {
87
+ return _colgroup.getResizerMinWidth;
88
+ }
89
+ });
84
90
  Object.defineProperty(exports, "getTableContainerElementWidth", {
85
91
  enumerable: true,
86
92
  get: function get() {
@@ -12,10 +12,10 @@ var _react = require("react");
12
12
  var _reactDom = _interopRequireDefault(require("react-dom"));
13
13
  var _reactIntlNext = require("react-intl-next");
14
14
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
15
- var _table3 = require("@atlaskit/editor-common/table");
16
15
  var _types = require("@atlaskit/editor-common/types");
17
16
  var _view = require("@atlaskit/editor-prosemirror/view");
18
17
  var _tableMap = require("@atlaskit/editor-tables/table-map");
18
+ var _SortingIconWrapper = require("../../ui/icons/SortingIconWrapper");
19
19
  var _pluginFactory = require("../plugin-factory");
20
20
  var _consts = require("./consts");
21
21
  var _pluginKey = require("./plugin-key");
@@ -29,7 +29,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
29
29
  * Instead of making changes to the ProseMirror document, the plugin sorts the table rows in the DOM. This allows the sorting to be
30
30
  * visible to the user without affecting the document's content.
31
31
  */
32
- var createPlugin = exports.createPlugin = function createPlugin(editorViewModeAPI) {
32
+ var createPlugin = exports.createPlugin = function createPlugin(api) {
33
33
  return new _safePlugin.SafePlugin({
34
34
  state: {
35
35
  init: function init() {
@@ -40,9 +40,10 @@ var createPlugin = exports.createPlugin = function createPlugin(editorViewModeAP
40
40
  };
41
41
  },
42
42
  apply: function apply(tr, pluginState, oldState) {
43
+ var _api$editorViewMode;
43
44
  // TODO - move this mode check to plugin creation if possible. Right now it's here because the initial state
44
45
  // does not appear correct when the plugin is created.
45
- var _ref = (editorViewModeAPI === null || editorViewModeAPI === void 0 ? void 0 : editorViewModeAPI.sharedState.currentState()) || {},
46
+ var _ref = ((_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState()) || {},
46
47
  mode = _ref.mode;
47
48
  if (mode !== 'view') {
48
49
  return pluginState;
@@ -101,7 +102,6 @@ var createPlugin = exports.createPlugin = function createPlugin(editorViewModeAP
101
102
  var map = _tableMap.TableMap.get(tableNode);
102
103
  var hasMergedCells = new Set(map.map).size !== map.map.length;
103
104
  map.mapByRow[0].forEach(function (cell, index) {
104
- // return pluginState;
105
105
  decs.push(_view.Decoration.widget(cell + pos + 2, function () {
106
106
  var _sort$tableId;
107
107
  var element = document.createElement('div');
@@ -121,11 +121,12 @@ var createPlugin = exports.createPlugin = function createPlugin(editorViewModeAP
121
121
  getIntl = _getPluginState.getIntl;
122
122
  _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_reactIntlNext.RawIntlProvider, {
123
123
  value: getIntl()
124
- }, /*#__PURE__*/(0, _react.createElement)(_table3.SortingIcon, {
124
+ }, /*#__PURE__*/(0, _react.createElement)(_SortingIconWrapper.SortingIconWrapper, {
125
125
  isSortingAllowed: !hasMergedCells,
126
126
  sortOrdered: sortOrdered,
127
127
  onClick: function onClick() {},
128
- onKeyDown: function onKeyDown() {}
128
+ onKeyDown: function onKeyDown() {},
129
+ api: api
129
130
  })), element);
130
131
  return element;
131
132
  }));
@@ -152,9 +153,9 @@ var createPlugin = exports.createPlugin = function createPlugin(editorViewModeAP
152
153
  },
153
154
  key: _pluginKey.tableViewModeSortPluginKey,
154
155
  appendTransaction: function appendTransaction(trs, oldState, newState) {
155
- var _key$getState;
156
+ var _api$editorViewMode2, _key$getState;
156
157
  // return newState.tr;
157
- var _ref8 = (editorViewModeAPI === null || editorViewModeAPI === void 0 ? void 0 : editorViewModeAPI.sharedState.currentState()) || {},
158
+ var _ref8 = (api === null || api === void 0 || (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 ? void 0 : _api$editorViewMode2.sharedState.currentState()) || {},
158
159
  mode = _ref8.mode;
159
160
  if (mode !== 'view') {
160
161
  return newState.tr;
package/dist/cjs/toDOM.js CHANGED
@@ -33,6 +33,7 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
33
33
  v = _ref2[1];
34
34
  return "".concat((0, _kebabCase.default)(k), ": ").concat((0, _kebabCase.default)(v));
35
35
  }).join(';');
36
+ var tableMinWidth = (0, _colgroup.getResizerMinWidth)(node);
36
37
  var attrs = _objectSpread({
37
38
  'data-number-column': node.attrs.isNumberColumnEnabled,
38
39
  'data-layout': node.attrs.layout,
@@ -91,7 +92,7 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
91
92
  boxSizing: 'border-box',
92
93
  '--ak-editor-table-gutter-padding': "".concat(gutterPadding, "px"),
93
94
  '--ak-editor-table-max-width': "".concat(_consts.TABLE_MAX_WIDTH, "px"),
94
- '--ak-editor-table-min-width': "145px",
95
+ '--ak-editor-table-min-width': "".concat(tableMinWidth, "px"),
95
96
  minWidth: 'var(--ak-editor-table-min-width)',
96
97
  maxWidth: "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))",
97
98
  width: "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ".concat(node.attrs.width, ")")
@@ -100,7 +101,7 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
100
101
  userSelect: 'auto',
101
102
  boxSizing: 'border-box',
102
103
  height: 'auto',
103
- minWidth: '145px',
104
+ minWidth: "".concat(tableMinWidth, "px"),
104
105
  maxWidth: "".concat(editorWidthFromGetter, "px"),
105
106
  width: "".concat(editorWidthFromGetter, "px;")
106
107
  })
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SortingIconWrapper = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _hooks = require("@atlaskit/editor-common/hooks");
10
+ var _table = require("@atlaskit/editor-common/table");
11
+ var SortingIconWrapper = exports.SortingIconWrapper = function SortingIconWrapper(props) {
12
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(props.api, ['editorViewMode']),
13
+ editorViewModeState = _useSharedPluginState.editorViewModeState;
14
+ if ((editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'edit') {
15
+ return null;
16
+ }
17
+ return /*#__PURE__*/_react.default.createElement(_table.SortingIcon, props);
18
+ };
@@ -339,7 +339,7 @@ class TableComponent extends React.Component {
339
339
  }
340
340
  }
341
341
  componentDidMount() {
342
- var _this$props$pluginInj, _this$props$pluginInj2, _this$table2, _this$table3;
342
+ var _this$table, _this$table2, _this$table3;
343
343
  const {
344
344
  allowColumnResizing,
345
345
  eventDispatcher,
@@ -349,13 +349,7 @@ class TableComponent extends React.Component {
349
349
  getEditorFeatureFlags,
350
350
  isTableScalingEnabled
351
351
  } = this.props;
352
- const {
353
- mode
354
- } = ((_this$props$pluginInj = this.props.pluginInjectionApi) === null || _this$props$pluginInj === void 0 ? void 0 : (_this$props$pluginInj2 = _this$props$pluginInj.editorViewMode) === null || _this$props$pluginInj2 === void 0 ? void 0 : _this$props$pluginInj2.sharedState.currentState()) || {};
355
- if (mode === 'view') {
356
- var _this$table;
357
- this === null || this === void 0 ? void 0 : (_this$table = this.table) === null || _this$table === void 0 ? void 0 : _this$table.addEventListener('mouseenter', this.handleMouseEnter);
358
- }
352
+ this === null || this === void 0 ? void 0 : (_this$table = this.table) === null || _this$table === void 0 ? void 0 : _this$table.addEventListener('mouseenter', this.handleMouseEnter);
359
353
  this === null || this === void 0 ? void 0 : (_this$table2 = this.table) === null || _this$table2 === void 0 ? void 0 : _this$table2.addEventListener('mouseout', this.handleMouseOut);
360
354
  this === null || this === void 0 ? void 0 : (_this$table3 = this.table) === null || _this$table3 === void 0 ? void 0 : _this$table3.addEventListener('mouseover', this.handleMouseOver);
361
355
  const {
@@ -625,8 +619,8 @@ class TableComponent extends React.Component {
625
619
  const isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(currentTable, previousTable);
626
620
  const isNoOfRowsChanged = tablesHaveDifferentNoOfRows(currentTable, previousTable);
627
621
  if (isNoOfColumnsChanged || isNoOfRowsChanged) {
628
- var _this$props$pluginInj3, _this$props$pluginInj4;
629
- (_this$props$pluginInj3 = this.props.pluginInjectionApi) === null || _this$props$pluginInj3 === void 0 ? void 0 : (_this$props$pluginInj4 = _this$props$pluginInj3.accessibilityUtils) === null || _this$props$pluginInj4 === void 0 ? void 0 : _this$props$pluginInj4.actions.ariaNotify(getAssistiveMessage(previousTable, currentTable, this.props.intl), {
622
+ var _this$props$pluginInj, _this$props$pluginInj2;
623
+ (_this$props$pluginInj = this.props.pluginInjectionApi) === null || _this$props$pluginInj === void 0 ? void 0 : (_this$props$pluginInj2 = _this$props$pluginInj.accessibilityUtils) === null || _this$props$pluginInj2 === void 0 ? void 0 : _this$props$pluginInj2.actions.ariaNotify(getAssistiveMessage(previousTable, currentTable, this.props.intl), {
630
624
  priority: 'important'
631
625
  });
632
626
  }
@@ -263,7 +263,7 @@ const tablesPlugin = ({
263
263
  }, {
264
264
  name: 'tableViewModeSort',
265
265
  plugin: () => {
266
- return api !== null && api !== void 0 && api.editorViewMode ? createViewModeSortPlugin(api.editorViewMode) : undefined;
266
+ return api !== null && api !== void 0 && api.editorViewMode ? createViewModeSortPlugin(api) : undefined;
267
267
  }
268
268
  }, {
269
269
  name: 'tableLocalId',
@@ -2,6 +2,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
2
  import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
3
3
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
+ import { COLUMN_MIN_WIDTH } from './consts';
5
6
  import { getScalingPercentForTableWithoutWidth, getTableScalingPercent } from './misc';
6
7
  /**
7
8
  * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
@@ -91,4 +92,11 @@ function renderColgroupFromNode(table, maybeTableRef, shouldUseIncreasedScalingP
91
92
  export const getColgroupChildrenLength = table => {
92
93
  const map = TableMap.get(table);
93
94
  return map.width;
95
+ };
96
+ export const getResizerMinWidth = node => {
97
+ const currentColumnCount = getColgroupChildrenLength(node);
98
+ const minColumnWidth = Math.min(3, currentColumnCount) * COLUMN_MIN_WIDTH;
99
+ // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
100
+ // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
101
+ return minColumnWidth + 1;
94
102
  };
@@ -1,4 +1,4 @@
1
- export { generateColgroup, insertColgroupFromNode, hasTableBeenResized, getColgroupChildrenLength } from './colgroup';
1
+ export { generateColgroup, insertColgroupFromNode, hasTableBeenResized, getColgroupChildrenLength, getResizerMinWidth } from './colgroup';
2
2
  export { contentWidth } from './content-width';
3
3
  export { getCellsRefsInColumn, calculateColumnWidth } from './column-state';
4
4
  export { getResizeState, updateColgroup, evenAllColumnsWidths } from './resize-state';
@@ -8,15 +8,15 @@ import { createElement } from 'react';
8
8
  import ReactDOM from 'react-dom';
9
9
  import { RawIntlProvider } from 'react-intl-next';
10
10
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
11
- import { SortingIcon } from '@atlaskit/editor-common/table';
12
11
  import { SortOrder } from '@atlaskit/editor-common/types';
13
12
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
14
13
  import { TableMap } from '@atlaskit/editor-tables/table-map';
14
+ import { SortingIconWrapper } from '../../ui/icons/SortingIconWrapper';
15
15
  import { getPluginState } from '../plugin-factory';
16
16
  import { IS_DISABLED_CLASS_NAME, SORT_INDEX_DATA_ATTRIBUTE, SORTING_ICON_CLASS_NAME } from './consts';
17
17
  import { tableViewModeSortPluginKey as key } from './plugin-key';
18
18
  import { getTableElements, toggleSort } from './utils';
19
- export const createPlugin = editorViewModeAPI => {
19
+ export const createPlugin = api => {
20
20
  return new SafePlugin({
21
21
  state: {
22
22
  init: () => ({
@@ -25,11 +25,12 @@ export const createPlugin = editorViewModeAPI => {
25
25
  allTables: []
26
26
  }),
27
27
  apply(tr, pluginState, oldState) {
28
+ var _api$editorViewMode;
28
29
  // TODO - move this mode check to plugin creation if possible. Right now it's here because the initial state
29
30
  // does not appear correct when the plugin is created.
30
31
  const {
31
32
  mode
32
- } = (editorViewModeAPI === null || editorViewModeAPI === void 0 ? void 0 : editorViewModeAPI.sharedState.currentState()) || {};
33
+ } = ((_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState()) || {};
33
34
  if (mode !== 'view') {
34
35
  return pluginState;
35
36
  }
@@ -77,7 +78,6 @@ export const createPlugin = editorViewModeAPI => {
77
78
  const map = TableMap.get(tableNode);
78
79
  const hasMergedCells = new Set(map.map).size !== map.map.length;
79
80
  map.mapByRow[0].forEach((cell, index) => {
80
- // return pluginState;
81
81
  decs.push(Decoration.widget(cell + pos + 2, () => {
82
82
  var _sort$tableId;
83
83
  const element = document.createElement('div');
@@ -98,11 +98,12 @@ export const createPlugin = editorViewModeAPI => {
98
98
  } = getPluginState(oldState);
99
99
  ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
100
100
  value: getIntl()
101
- }, /*#__PURE__*/createElement(SortingIcon, {
101
+ }, /*#__PURE__*/createElement(SortingIconWrapper, {
102
102
  isSortingAllowed: !hasMergedCells,
103
103
  sortOrdered,
104
104
  onClick: () => {},
105
- onKeyDown: () => {}
105
+ onKeyDown: () => {},
106
+ api
106
107
  })), element);
107
108
  return element;
108
109
  }));
@@ -129,11 +130,11 @@ export const createPlugin = editorViewModeAPI => {
129
130
  },
130
131
  key,
131
132
  appendTransaction: (trs, oldState, newState) => {
132
- var _key$getState;
133
+ var _api$editorViewMode2, _key$getState;
133
134
  // return newState.tr;
134
135
  const {
135
136
  mode
136
- } = (editorViewModeAPI === null || editorViewModeAPI === void 0 ? void 0 : editorViewModeAPI.sharedState.currentState()) || {};
137
+ } = (api === null || api === void 0 ? void 0 : (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 ? void 0 : _api$editorViewMode2.sharedState.currentState()) || {};
137
138
  if (mode !== 'view') {
138
139
  return newState.tr;
139
140
  }
@@ -5,7 +5,7 @@ import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
7
7
  import { getAlignmentStyle } from './nodeviews/table-container-styles';
8
- import { generateColgroup } from './pm-plugins/table-resizing/utils/colgroup';
8
+ import { generateColgroup, getResizerMinWidth } from './pm-plugins/table-resizing/utils/colgroup';
9
9
  import { TABLE_MAX_WIDTH } from './pm-plugins/table-resizing/utils/consts';
10
10
  export const tableNodeSpecWithFixedToDOM = config => {
11
11
  if (editorExperiment('platform_editor_exp_lazy_node_views', false)) {
@@ -17,6 +17,7 @@ export const tableNodeSpecWithFixedToDOM = config => {
17
17
  const gutterPadding = akEditorGutterPaddingDynamic() * 2;
18
18
  const editorWidthFromGetter = fg('platform_editor_breakout_use_css') ? undefined : Math.min(config.getEditorContainerWidth().width - gutterPadding, node.attrs.width);
19
19
  const alignmentStyle = Object.entries(getAlignmentStyle(node.attrs.layout)).map(([k, v]) => `${kebabCase(k)}: ${kebabCase(v)}`).join(';');
20
+ const tableMinWidth = getResizerMinWidth(node);
20
21
  const attrs = {
21
22
  'data-number-column': node.attrs.isNumberColumnEnabled,
22
23
  'data-layout': node.attrs.layout,
@@ -76,7 +77,7 @@ export const tableNodeSpecWithFixedToDOM = config => {
76
77
  boxSizing: 'border-box',
77
78
  '--ak-editor-table-gutter-padding': `${gutterPadding}px`,
78
79
  '--ak-editor-table-max-width': `${TABLE_MAX_WIDTH}px`,
79
- '--ak-editor-table-min-width': `145px`,
80
+ '--ak-editor-table-min-width': `${tableMinWidth}px`,
80
81
  minWidth: 'var(--ak-editor-table-min-width)',
81
82
  maxWidth: `min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))`,
82
83
  width: `min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ${node.attrs.width})`
@@ -85,7 +86,7 @@ export const tableNodeSpecWithFixedToDOM = config => {
85
86
  userSelect: 'auto',
86
87
  boxSizing: 'border-box',
87
88
  height: 'auto',
88
- minWidth: '145px',
89
+ minWidth: `${tableMinWidth}px`,
89
90
  maxWidth: `${editorWidthFromGetter}px`,
90
91
  width: `${editorWidthFromGetter}px;`
91
92
  })
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { SortingIcon } from '@atlaskit/editor-common/table';
4
+ export const SortingIconWrapper = props => {
5
+ const {
6
+ editorViewModeState
7
+ } = useSharedPluginState(props.api, ['editorViewMode']);
8
+ if ((editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'edit') {
9
+ return null;
10
+ }
11
+ return /*#__PURE__*/React.createElement(SortingIcon, props);
12
+ };
@@ -351,7 +351,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
351
351
  _createClass(TableComponent, [{
352
352
  key: "componentDidMount",
353
353
  value: function componentDidMount() {
354
- var _this$props$pluginInj, _this$table2, _this$table3;
354
+ var _this$table, _this$table2, _this$table3;
355
355
  var _this$props7 = this.props,
356
356
  allowColumnResizing = _this$props7.allowColumnResizing,
357
357
  eventDispatcher = _this$props7.eventDispatcher,
@@ -360,12 +360,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
360
360
  getNode = _this$props7.getNode,
361
361
  getEditorFeatureFlags = _this$props7.getEditorFeatureFlags,
362
362
  isTableScalingEnabled = _this$props7.isTableScalingEnabled;
363
- var _ref = ((_this$props$pluginInj = this.props.pluginInjectionApi) === null || _this$props$pluginInj === void 0 || (_this$props$pluginInj = _this$props$pluginInj.editorViewMode) === null || _this$props$pluginInj === void 0 ? void 0 : _this$props$pluginInj.sharedState.currentState()) || {},
364
- mode = _ref.mode;
365
- if (mode === 'view') {
366
- var _this$table;
367
- this === null || this === void 0 || (_this$table = this.table) === null || _this$table === void 0 || _this$table.addEventListener('mouseenter', this.handleMouseEnter);
368
- }
363
+ this === null || this === void 0 || (_this$table = this.table) === null || _this$table === void 0 || _this$table.addEventListener('mouseenter', this.handleMouseEnter);
369
364
  this === null || this === void 0 || (_this$table2 = this.table) === null || _this$table2 === void 0 || _this$table2.addEventListener('mouseout', this.handleMouseOut);
370
365
  this === null || this === void 0 || (_this$table3 = this.table) === null || _this$table3 === void 0 || _this$table3.addEventListener('mouseover', this.handleMouseOver);
371
366
  var _getEditorFeatureFlag = getEditorFeatureFlags(),
@@ -640,8 +635,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
640
635
  var isNoOfColumnsChanged = tablesHaveDifferentNoOfColumns(currentTable, previousTable);
641
636
  var isNoOfRowsChanged = tablesHaveDifferentNoOfRows(currentTable, previousTable);
642
637
  if (isNoOfColumnsChanged || isNoOfRowsChanged) {
643
- var _this$props$pluginInj2;
644
- (_this$props$pluginInj2 = this.props.pluginInjectionApi) === null || _this$props$pluginInj2 === void 0 || (_this$props$pluginInj2 = _this$props$pluginInj2.accessibilityUtils) === null || _this$props$pluginInj2 === void 0 || _this$props$pluginInj2.actions.ariaNotify(getAssistiveMessage(previousTable, currentTable, this.props.intl), {
638
+ var _this$props$pluginInj;
639
+ (_this$props$pluginInj = this.props.pluginInjectionApi) === null || _this$props$pluginInj === void 0 || (_this$props$pluginInj = _this$props$pluginInj.accessibilityUtils) === null || _this$props$pluginInj === void 0 || _this$props$pluginInj.actions.ariaNotify(getAssistiveMessage(previousTable, currentTable, this.props.intl), {
645
640
  priority: 'important'
646
641
  });
647
642
  }
@@ -268,7 +268,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
268
268
  }, {
269
269
  name: 'tableViewModeSort',
270
270
  plugin: function plugin() {
271
- return api !== null && api !== void 0 && api.editorViewMode ? createViewModeSortPlugin(api.editorViewMode) : undefined;
271
+ return api !== null && api !== void 0 && api.editorViewMode ? createViewModeSortPlugin(api) : undefined;
272
272
  }
273
273
  }, {
274
274
  name: 'tableLocalId',
@@ -3,6 +3,7 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
3
3
  import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
4
4
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
+ import { COLUMN_MIN_WIDTH } from './consts';
6
7
  import { getScalingPercentForTableWithoutWidth, getTableScalingPercent } from './misc';
7
8
  /**
8
9
  * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
@@ -102,4 +103,11 @@ function renderColgroupFromNode(table, maybeTableRef, shouldUseIncreasedScalingP
102
103
  export var getColgroupChildrenLength = function getColgroupChildrenLength(table) {
103
104
  var map = TableMap.get(table);
104
105
  return map.width;
106
+ };
107
+ export var getResizerMinWidth = function getResizerMinWidth(node) {
108
+ var currentColumnCount = getColgroupChildrenLength(node);
109
+ var minColumnWidth = Math.min(3, currentColumnCount) * COLUMN_MIN_WIDTH;
110
+ // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
111
+ // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
112
+ return minColumnWidth + 1;
105
113
  };
@@ -1,4 +1,4 @@
1
- export { generateColgroup, insertColgroupFromNode, hasTableBeenResized, getColgroupChildrenLength } from './colgroup';
1
+ export { generateColgroup, insertColgroupFromNode, hasTableBeenResized, getColgroupChildrenLength, getResizerMinWidth } from './colgroup';
2
2
  export { contentWidth } from './content-width';
3
3
  export { getCellsRefsInColumn, calculateColumnWidth } from './column-state';
4
4
  export { getResizeState, updateColgroup, evenAllColumnsWidths } from './resize-state';
@@ -16,15 +16,15 @@ import { createElement } from 'react';
16
16
  import ReactDOM from 'react-dom';
17
17
  import { RawIntlProvider } from 'react-intl-next';
18
18
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
19
- import { SortingIcon } from '@atlaskit/editor-common/table';
20
19
  import { SortOrder } from '@atlaskit/editor-common/types';
21
20
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
22
21
  import { TableMap } from '@atlaskit/editor-tables/table-map';
22
+ import { SortingIconWrapper } from '../../ui/icons/SortingIconWrapper';
23
23
  import { getPluginState } from '../plugin-factory';
24
24
  import { IS_DISABLED_CLASS_NAME, SORT_INDEX_DATA_ATTRIBUTE, SORTING_ICON_CLASS_NAME } from './consts';
25
25
  import { tableViewModeSortPluginKey as key } from './plugin-key';
26
26
  import { getTableElements, toggleSort } from './utils';
27
- export var createPlugin = function createPlugin(editorViewModeAPI) {
27
+ export var createPlugin = function createPlugin(api) {
28
28
  return new SafePlugin({
29
29
  state: {
30
30
  init: function init() {
@@ -35,9 +35,10 @@ export var createPlugin = function createPlugin(editorViewModeAPI) {
35
35
  };
36
36
  },
37
37
  apply: function apply(tr, pluginState, oldState) {
38
+ var _api$editorViewMode;
38
39
  // TODO - move this mode check to plugin creation if possible. Right now it's here because the initial state
39
40
  // does not appear correct when the plugin is created.
40
- var _ref = (editorViewModeAPI === null || editorViewModeAPI === void 0 ? void 0 : editorViewModeAPI.sharedState.currentState()) || {},
41
+ var _ref = ((_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState()) || {},
41
42
  mode = _ref.mode;
42
43
  if (mode !== 'view') {
43
44
  return pluginState;
@@ -96,7 +97,6 @@ export var createPlugin = function createPlugin(editorViewModeAPI) {
96
97
  var map = TableMap.get(tableNode);
97
98
  var hasMergedCells = new Set(map.map).size !== map.map.length;
98
99
  map.mapByRow[0].forEach(function (cell, index) {
99
- // return pluginState;
100
100
  decs.push(Decoration.widget(cell + pos + 2, function () {
101
101
  var _sort$tableId;
102
102
  var element = document.createElement('div');
@@ -116,11 +116,12 @@ export var createPlugin = function createPlugin(editorViewModeAPI) {
116
116
  getIntl = _getPluginState.getIntl;
117
117
  ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
118
118
  value: getIntl()
119
- }, /*#__PURE__*/createElement(SortingIcon, {
119
+ }, /*#__PURE__*/createElement(SortingIconWrapper, {
120
120
  isSortingAllowed: !hasMergedCells,
121
121
  sortOrdered: sortOrdered,
122
122
  onClick: function onClick() {},
123
- onKeyDown: function onKeyDown() {}
123
+ onKeyDown: function onKeyDown() {},
124
+ api: api
124
125
  })), element);
125
126
  return element;
126
127
  }));
@@ -147,9 +148,9 @@ export var createPlugin = function createPlugin(editorViewModeAPI) {
147
148
  },
148
149
  key: key,
149
150
  appendTransaction: function appendTransaction(trs, oldState, newState) {
150
- var _key$getState;
151
+ var _api$editorViewMode2, _key$getState;
151
152
  // return newState.tr;
152
- var _ref8 = (editorViewModeAPI === null || editorViewModeAPI === void 0 ? void 0 : editorViewModeAPI.sharedState.currentState()) || {},
153
+ var _ref8 = (api === null || api === void 0 || (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 ? void 0 : _api$editorViewMode2.sharedState.currentState()) || {},
153
154
  mode = _ref8.mode;
154
155
  if (mode !== 'view') {
155
156
  return newState.tr;
package/dist/esm/toDOM.js CHANGED
@@ -10,7 +10,7 @@ import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
10
10
  import { fg } from '@atlaskit/platform-feature-flags';
11
11
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
12
12
  import { getAlignmentStyle } from './nodeviews/table-container-styles';
13
- import { generateColgroup } from './pm-plugins/table-resizing/utils/colgroup';
13
+ import { generateColgroup, getResizerMinWidth } from './pm-plugins/table-resizing/utils/colgroup';
14
14
  import { TABLE_MAX_WIDTH } from './pm-plugins/table-resizing/utils/consts';
15
15
  export var tableNodeSpecWithFixedToDOM = function tableNodeSpecWithFixedToDOM(config) {
16
16
  if (editorExperiment('platform_editor_exp_lazy_node_views', false)) {
@@ -26,6 +26,7 @@ export var tableNodeSpecWithFixedToDOM = function tableNodeSpecWithFixedToDOM(co
26
26
  v = _ref2[1];
27
27
  return "".concat(kebabCase(k), ": ").concat(kebabCase(v));
28
28
  }).join(';');
29
+ var tableMinWidth = getResizerMinWidth(node);
29
30
  var attrs = _objectSpread({
30
31
  'data-number-column': node.attrs.isNumberColumnEnabled,
31
32
  'data-layout': node.attrs.layout,
@@ -84,7 +85,7 @@ export var tableNodeSpecWithFixedToDOM = function tableNodeSpecWithFixedToDOM(co
84
85
  boxSizing: 'border-box',
85
86
  '--ak-editor-table-gutter-padding': "".concat(gutterPadding, "px"),
86
87
  '--ak-editor-table-max-width': "".concat(TABLE_MAX_WIDTH, "px"),
87
- '--ak-editor-table-min-width': "145px",
88
+ '--ak-editor-table-min-width': "".concat(tableMinWidth, "px"),
88
89
  minWidth: 'var(--ak-editor-table-min-width)',
89
90
  maxWidth: "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))",
90
91
  width: "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ".concat(node.attrs.width, ")")
@@ -93,7 +94,7 @@ export var tableNodeSpecWithFixedToDOM = function tableNodeSpecWithFixedToDOM(co
93
94
  userSelect: 'auto',
94
95
  boxSizing: 'border-box',
95
96
  height: 'auto',
96
- minWidth: '145px',
97
+ minWidth: "".concat(tableMinWidth, "px"),
97
98
  maxWidth: "".concat(editorWidthFromGetter, "px"),
98
99
  width: "".concat(editorWidthFromGetter, "px;")
99
100
  })
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { SortingIcon } from '@atlaskit/editor-common/table';
4
+ export var SortingIconWrapper = function SortingIconWrapper(props) {
5
+ var _useSharedPluginState = useSharedPluginState(props.api, ['editorViewMode']),
6
+ editorViewModeState = _useSharedPluginState.editorViewModeState;
7
+ if ((editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'edit') {
8
+ return null;
9
+ }
10
+ return /*#__PURE__*/React.createElement(SortingIcon, props);
11
+ };
@@ -21,4 +21,5 @@ export declare const hasTableColumnBeenResized: (table: PmNode) => boolean;
21
21
  */
22
22
  export declare const isMinCellWidthTable: (table: PmNode) => boolean;
23
23
  export declare const getColgroupChildrenLength: (table: PmNode) => number;
24
+ export declare const getResizerMinWidth: (node: PmNode) => number;
24
25
  export {};
@@ -1,4 +1,4 @@
1
- export { generateColgroup, insertColgroupFromNode, hasTableBeenResized, getColgroupChildrenLength, } from './colgroup';
1
+ export { generateColgroup, insertColgroupFromNode, hasTableBeenResized, getColgroupChildrenLength, getResizerMinWidth, } from './colgroup';
2
2
  export { contentWidth } from './content-width';
3
3
  export { getCellsRefsInColumn, calculateColumnWidth } from './column-state';
4
4
  export { getResizeState, updateColgroup, evenAllColumnsWidths } from './resize-state';
@@ -7,4 +7,4 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
8
8
  import type tablePlugin from '../../plugin';
9
9
  import type { ViewModeSortPluginState } from './types';
10
- export declare const createPlugin: (editorViewModeAPI: ExtractInjectionAPI<typeof tablePlugin>['editorViewMode']) => SafePlugin<ViewModeSortPluginState>;
10
+ export declare const createPlugin: (api: ExtractInjectionAPI<typeof tablePlugin>) => SafePlugin<ViewModeSortPluginState>;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { SortingIcon } from '@atlaskit/editor-common/table';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import type { TablePlugin } from '../../plugin';
5
+ type SortingIconProps = React.ComponentProps<typeof SortingIcon>;
6
+ type SortingIconWrapperProps = SortingIconProps & {
7
+ api: ExtractInjectionAPI<TablePlugin>;
8
+ };
9
+ export declare const SortingIconWrapper: (props: SortingIconWrapperProps) => JSX.Element | null;
10
+ export {};
@@ -21,4 +21,5 @@ export declare const hasTableColumnBeenResized: (table: PmNode) => boolean;
21
21
  */
22
22
  export declare const isMinCellWidthTable: (table: PmNode) => boolean;
23
23
  export declare const getColgroupChildrenLength: (table: PmNode) => number;
24
+ export declare const getResizerMinWidth: (node: PmNode) => number;
24
25
  export {};
@@ -1,4 +1,4 @@
1
- export { generateColgroup, insertColgroupFromNode, hasTableBeenResized, getColgroupChildrenLength, } from './colgroup';
1
+ export { generateColgroup, insertColgroupFromNode, hasTableBeenResized, getColgroupChildrenLength, getResizerMinWidth, } from './colgroup';
2
2
  export { contentWidth } from './content-width';
3
3
  export { getCellsRefsInColumn, calculateColumnWidth } from './column-state';
4
4
  export { getResizeState, updateColgroup, evenAllColumnsWidths } from './resize-state';
@@ -7,4 +7,4 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
8
8
  import type tablePlugin from '../../plugin';
9
9
  import type { ViewModeSortPluginState } from './types';
10
- export declare const createPlugin: (editorViewModeAPI: ExtractInjectionAPI<typeof tablePlugin>['editorViewMode']) => SafePlugin<ViewModeSortPluginState>;
10
+ export declare const createPlugin: (api: ExtractInjectionAPI<typeof tablePlugin>) => SafePlugin<ViewModeSortPluginState>;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { SortingIcon } from '@atlaskit/editor-common/table';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import type { TablePlugin } from '../../plugin';
5
+ type SortingIconProps = React.ComponentProps<typeof SortingIcon>;
6
+ type SortingIconWrapperProps = SortingIconProps & {
7
+ api: ExtractInjectionAPI<TablePlugin>;
8
+ };
9
+ export declare const SortingIconWrapper: (props: SortingIconWrapperProps) => JSX.Element | null;
10
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.28.7",
3
+ "version": "7.28.9",
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
  "@atlaskit/adf-schema": "^40.9.0",
31
31
  "@atlaskit/button": "^20.2.0",
32
32
  "@atlaskit/custom-steps": "^0.7.0",
33
- "@atlaskit/editor-common": "^93.0.0",
33
+ "@atlaskit/editor-common": "^93.1.0",
34
34
  "@atlaskit/editor-palette": "1.6.1",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.8.0",
@@ -43,7 +43,7 @@
43
43
  "@atlaskit/editor-prosemirror": "6.0.0",
44
44
  "@atlaskit/editor-shared-styles": "^3.0.0",
45
45
  "@atlaskit/editor-tables": "^2.8.0",
46
- "@atlaskit/icon": "^22.20.0",
46
+ "@atlaskit/icon": "^22.22.0",
47
47
  "@atlaskit/menu": "^2.12.0",
48
48
  "@atlaskit/platform-feature-flags": "^0.3.0",
49
49
  "@atlaskit/pragmatic-drag-and-drop": "^1.3.0",
@@ -51,7 +51,7 @@
51
51
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
52
52
  "@atlaskit/primitives": "^12.2.0",
53
53
  "@atlaskit/theme": "^13.0.0",
54
- "@atlaskit/tmp-editor-statsig": "^2.2.0",
54
+ "@atlaskit/tmp-editor-statsig": "^2.3.0",
55
55
  "@atlaskit/toggle": "^13.4.0",
56
56
  "@atlaskit/tokens": "^2.0.0",
57
57
  "@atlaskit/tooltip": "^18.8.0",
@@ -228,11 +228,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
228
228
  isTableScalingEnabled,
229
229
  } = this.props;
230
230
 
231
- const { mode } =
232
- this.props.pluginInjectionApi?.editorViewMode?.sharedState.currentState() || {};
233
- if (mode === 'view') {
234
- this?.table?.addEventListener('mouseenter', this.handleMouseEnter);
235
- }
231
+ this?.table?.addEventListener('mouseenter', this.handleMouseEnter);
236
232
 
237
233
  this?.table?.addEventListener('mouseout', this.handleMouseOut);
238
234
 
package/src/plugin.tsx CHANGED
@@ -436,7 +436,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
436
436
  {
437
437
  name: 'tableViewModeSort',
438
438
  plugin: () => {
439
- return api?.editorViewMode ? createViewModeSortPlugin(api.editorViewMode) : undefined;
439
+ return api?.editorViewMode ? createViewModeSortPlugin(api) : undefined;
440
440
  },
441
441
  },
442
442
  {
@@ -4,6 +4,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
5
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
6
 
7
+ import { COLUMN_MIN_WIDTH } from './consts';
7
8
  import { getScalingPercentForTableWithoutWidth, getTableScalingPercent } from './misc';
8
9
 
9
10
  type Col = Array<string | { [name: string]: string }>;
@@ -152,3 +153,11 @@ export const getColgroupChildrenLength = (table: PmNode): number => {
152
153
  const map = TableMap.get(table);
153
154
  return map.width;
154
155
  };
156
+
157
+ export const getResizerMinWidth = (node: PmNode) => {
158
+ const currentColumnCount = getColgroupChildrenLength(node);
159
+ const minColumnWidth = Math.min(3, currentColumnCount) * COLUMN_MIN_WIDTH;
160
+ // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
161
+ // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
162
+ return minColumnWidth + 1;
163
+ };
@@ -3,6 +3,7 @@ export {
3
3
  insertColgroupFromNode,
4
4
  hasTableBeenResized,
5
5
  getColgroupChildrenLength,
6
+ getResizerMinWidth,
6
7
  } from './colgroup';
7
8
  export { contentWidth } from './content-width';
8
9
  export { getCellsRefsInColumn, calculateColumnWidth } from './column-state';
@@ -10,13 +10,13 @@ import ReactDOM from 'react-dom';
10
10
  import { RawIntlProvider } from 'react-intl-next';
11
11
 
12
12
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
13
- import { SortingIcon } from '@atlaskit/editor-common/table';
14
13
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
15
14
  import { SortOrder } from '@atlaskit/editor-common/types';
16
15
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
17
16
  import { TableMap } from '@atlaskit/editor-tables/table-map';
18
17
 
19
18
  import type tablePlugin from '../../plugin';
19
+ import { SortingIconWrapper } from '../../ui/icons/SortingIconWrapper';
20
20
  import { getPluginState } from '../plugin-factory';
21
21
 
22
22
  import {
@@ -28,9 +28,7 @@ import { tableViewModeSortPluginKey as key } from './plugin-key';
28
28
  import type { ViewModeSortPluginState } from './types';
29
29
  import { getTableElements, toggleSort } from './utils';
30
30
 
31
- export const createPlugin = (
32
- editorViewModeAPI: ExtractInjectionAPI<typeof tablePlugin>['editorViewMode'],
33
- ) => {
31
+ export const createPlugin = (api: ExtractInjectionAPI<typeof tablePlugin>) => {
34
32
  return new SafePlugin({
35
33
  state: {
36
34
  init: () => ({
@@ -41,7 +39,7 @@ export const createPlugin = (
41
39
  apply(tr, pluginState: ViewModeSortPluginState, oldState) {
42
40
  // TODO - move this mode check to plugin creation if possible. Right now it's here because the initial state
43
41
  // does not appear correct when the plugin is created.
44
- const { mode } = editorViewModeAPI?.sharedState.currentState() || {};
42
+ const { mode } = api.editorViewMode?.sharedState.currentState() || {};
45
43
  if (mode !== 'view') {
46
44
  return pluginState;
47
45
  }
@@ -86,7 +84,6 @@ export const createPlugin = (
86
84
  const map = TableMap.get(tableNode);
87
85
  const hasMergedCells = new Set(map.map).size !== map.map.length;
88
86
  map.mapByRow[0].forEach((cell, index) => {
89
- // return pluginState;
90
87
  decs.push(
91
88
  Decoration.widget(cell + pos + 2, () => {
92
89
  const element = document.createElement('div');
@@ -109,11 +106,12 @@ export const createPlugin = (
109
106
  createElement(
110
107
  RawIntlProvider,
111
108
  { value: getIntl() },
112
- createElement(SortingIcon, {
109
+ createElement(SortingIconWrapper, {
113
110
  isSortingAllowed: !hasMergedCells,
114
111
  sortOrdered,
115
112
  onClick: () => {},
116
113
  onKeyDown: () => {},
114
+ api,
117
115
  }),
118
116
  ),
119
117
  element,
@@ -146,7 +144,7 @@ export const createPlugin = (
146
144
  key,
147
145
  appendTransaction: (trs, oldState, newState) => {
148
146
  // return newState.tr;
149
- const { mode } = editorViewModeAPI?.sharedState.currentState() || {};
147
+ const { mode } = api?.editorViewMode?.sharedState.currentState() || {};
150
148
  if (mode !== 'view') {
151
149
  return newState.tr;
152
150
  }
package/src/toDOM.ts CHANGED
@@ -9,7 +9,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
10
 
11
11
  import { getAlignmentStyle } from './nodeviews/table-container-styles';
12
- import { generateColgroup } from './pm-plugins/table-resizing/utils/colgroup';
12
+ import { generateColgroup, getResizerMinWidth } from './pm-plugins/table-resizing/utils/colgroup';
13
13
  import { TABLE_MAX_WIDTH } from './pm-plugins/table-resizing/utils/consts';
14
14
 
15
15
  type Config = {
@@ -34,6 +34,8 @@ export const tableNodeSpecWithFixedToDOM = (config: Config): typeof table => {
34
34
  .map(([k, v]) => `${kebabCase(k)}: ${kebabCase(v)}`)
35
35
  .join(';');
36
36
 
37
+ const tableMinWidth = getResizerMinWidth(node);
38
+
37
39
  const attrs = {
38
40
  'data-number-column': node.attrs.isNumberColumnEnabled,
39
41
  'data-layout': node.attrs.layout,
@@ -145,7 +147,7 @@ export const tableNodeSpecWithFixedToDOM = (config: Config): typeof table => {
145
147
  boxSizing: 'border-box',
146
148
  '--ak-editor-table-gutter-padding': `${gutterPadding}px`,
147
149
  '--ak-editor-table-max-width': `${TABLE_MAX_WIDTH}px`,
148
- '--ak-editor-table-min-width': `145px`,
150
+ '--ak-editor-table-min-width': `${tableMinWidth}px`,
149
151
  minWidth: 'var(--ak-editor-table-min-width)',
150
152
  maxWidth: `min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))`,
151
153
  width: `min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ${node.attrs.width})`,
@@ -155,7 +157,7 @@ export const tableNodeSpecWithFixedToDOM = (config: Config): typeof table => {
155
157
  userSelect: 'auto',
156
158
  boxSizing: 'border-box',
157
159
  height: 'auto',
158
- minWidth: '145px',
160
+ minWidth: `${tableMinWidth}px`,
159
161
  maxWidth: `${editorWidthFromGetter}px`,
160
162
  width: `${editorWidthFromGetter}px;`,
161
163
  }),
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
+ import { SortingIcon } from '@atlaskit/editor-common/table';
5
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
6
+
7
+ import type { TablePlugin } from '../../plugin';
8
+
9
+ type SortingIconProps = React.ComponentProps<typeof SortingIcon>;
10
+ type SortingIconWrapperProps = SortingIconProps & {
11
+ api: ExtractInjectionAPI<TablePlugin>;
12
+ };
13
+
14
+ export const SortingIconWrapper = (props: SortingIconWrapperProps) => {
15
+ const { editorViewModeState } = useSharedPluginState(props.api, ['editorViewMode']);
16
+ if (editorViewModeState?.mode === 'edit') {
17
+ return null;
18
+ }
19
+ return <SortingIcon {...props} />;
20
+ };