@atlaskit/editor-plugin-table 2.8.0 → 2.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js CHANGED
@@ -1,6 +1,5 @@
1
1
  module.exports = {
2
2
  rules: {
3
- 'no-duplicate-imports': 'off',
4
3
  '@typescript-eslint/no-duplicate-imports': 'error',
5
4
  },
6
5
  };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 2.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.8.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`800c927efd1`](https://bitbucket.org/atlassian/atlassian-frontend/commits/800c927efd1) - [ux] ED-19317: fix numbered column shift up issue with custom table FF on
14
+
3
15
  ## 2.8.0
4
16
 
5
17
  ### Minor Changes
@@ -13,8 +13,8 @@ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
13
13
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
14
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
15
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
17
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
18
  var _react = _interopRequireDefault(require("react"));
19
19
  var _nodeWidth = require("@atlaskit/editor-common/node-width");
20
20
  var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
@@ -32,35 +32,38 @@ var _utils2 = require("../utils");
32
32
  var _TableComponent = _interopRequireDefault(require("./TableComponent"));
33
33
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
34
34
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
35
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
36
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
37
- var tableAttributes = function tableAttributes(node, options, state, pos) {
38
- // provide a width for tables when custom table width is supported
39
- // this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
40
- // support screen size adjustments
41
- var shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !(0, _utils2.isTableNested)(state, pos);
42
- var style = "width: ".concat(node.attrs.isNumberColumnEnabled ? (0, _nodeWidth.getTableContainerWidth)(node) - _editorSharedStyles.akEditorTableNumberColumnWidth : (0, _nodeWidth.getTableContainerWidth)(node), "px");
43
- var dataAttrsInTable = {
35
+ var tableAttributes = function tableAttributes(node) {
36
+ return {
44
37
  'data-number-column': node.attrs.isNumberColumnEnabled,
45
38
  'data-layout': node.attrs.layout,
46
39
  'data-autosize': node.attrs.__autoSize,
47
40
  'data-table-local-id': node.attrs.localId || '',
48
41
  'data-table-width': node.attrs.width
49
42
  };
50
- if (shouldHaveInlineWidth) {
51
- // this should be fixed because style will overwrite any existing styles, current found conflict with sticky headers
52
- return _objectSpread(_objectSpread({}, dataAttrsInTable), {}, {
53
- style: style
54
- });
43
+ };
44
+ var getInlineWidth = function getInlineWidth(node, options, state, pos) {
45
+ // provide a width for tables when custom table width is supported
46
+ // this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
47
+ // support screen size adjustments
48
+ var shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !(0, _utils2.isTableNested)(state, pos);
49
+ var widthValue = (0, _nodeWidth.getTableContainerWidth)(node);
50
+ if (node.attrs.isNumberColumnEnabled) {
51
+ widthValue -= _editorSharedStyles.akEditorTableNumberColumnWidth;
52
+ }
53
+ return shouldHaveInlineWidth ? widthValue : undefined;
54
+ };
55
+ var handleInlineTableWidth = function handleInlineTableWidth(table, width) {
56
+ if (!table || !width) {
57
+ return;
55
58
  }
56
- return dataAttrsInTable;
59
+ table.style.setProperty('width', "".concat(width, "px"));
57
60
  };
58
61
  var toDOM = function toDOM(node, props) {
59
62
  var colgroup = '';
60
63
  if (props.allowColumnResizing) {
61
64
  colgroup = ['colgroup', {}].concat((0, _toConsumableArray2.default)((0, _utils.generateColgroup)(node)));
62
65
  }
63
- return ['table', tableAttributes(node, props.options, props.view.state, props.getPos()), colgroup, ['tbody', 0]];
66
+ return ['table', tableAttributes(node), colgroup, ['tbody', 0]];
64
67
  };
65
68
  var TableView = /*#__PURE__*/function (_ReactNodeView) {
66
69
  (0, _inherits2.default)(TableView, _ReactNodeView);
@@ -82,8 +85,12 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
82
85
  key: "getContentDOM",
83
86
  value: function getContentDOM() {
84
87
  var rendered = _model.DOMSerializer.renderSpec(document, toDOM(this.node, this.reactComponentProps));
88
+ var tableInlineWidth = getInlineWidth(this.node, this.reactComponentProps.options, this.reactComponentProps.view.state, this.reactComponentProps.getPos());
85
89
  if (rendered.dom) {
86
90
  this.table = rendered.dom;
91
+ if (tableInlineWidth) {
92
+ handleInlineTableWidth(this.table, tableInlineWidth);
93
+ }
87
94
  }
88
95
  return rendered;
89
96
  }
@@ -94,10 +101,16 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
94
101
  if (!this.table) {
95
102
  return;
96
103
  }
97
- var attrs = tableAttributes(node, this.reactComponentProps.options, this.view.state, this.getPos());
104
+ var attrs = tableAttributes(node);
98
105
  Object.keys(attrs).forEach(function (attr) {
99
106
  _this2.table.setAttribute(attr, attrs[attr]);
100
107
  });
108
+
109
+ // handle inline style when table been resized
110
+ var tableInlineWidth = getInlineWidth(node, this.reactComponentProps.options, this.view.state, this.getPos());
111
+ if (tableInlineWidth) {
112
+ handleInlineTableWidth(this.table, tableInlineWidth);
113
+ }
101
114
  }
102
115
  }, {
103
116
  key: "render",
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "sideEffects": false
5
5
  }
@@ -14,34 +14,38 @@ import { generateColgroup } from '../pm-plugins/table-resizing/utils';
14
14
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
15
15
  import { isTableNested } from '../utils';
16
16
  import TableComponent from './TableComponent';
17
- const tableAttributes = (node, options, state, pos) => {
18
- // provide a width for tables when custom table width is supported
19
- // this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
20
- // support screen size adjustments
21
- const shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !isTableNested(state, pos);
22
- let style = `width: ${node.attrs.isNumberColumnEnabled ? getTableContainerWidth(node) - akEditorTableNumberColumnWidth : getTableContainerWidth(node)}px`;
23
- const dataAttrsInTable = {
17
+ const tableAttributes = node => {
18
+ return {
24
19
  'data-number-column': node.attrs.isNumberColumnEnabled,
25
20
  'data-layout': node.attrs.layout,
26
21
  'data-autosize': node.attrs.__autoSize,
27
22
  'data-table-local-id': node.attrs.localId || '',
28
23
  'data-table-width': node.attrs.width
29
24
  };
30
- if (shouldHaveInlineWidth) {
31
- // this should be fixed because style will overwrite any existing styles, current found conflict with sticky headers
32
- return {
33
- ...dataAttrsInTable,
34
- style
35
- };
25
+ };
26
+ const getInlineWidth = (node, options, state, pos) => {
27
+ // provide a width for tables when custom table width is supported
28
+ // this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
29
+ // support screen size adjustments
30
+ const shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !isTableNested(state, pos);
31
+ let widthValue = getTableContainerWidth(node);
32
+ if (node.attrs.isNumberColumnEnabled) {
33
+ widthValue -= akEditorTableNumberColumnWidth;
34
+ }
35
+ return shouldHaveInlineWidth ? widthValue : undefined;
36
+ };
37
+ const handleInlineTableWidth = (table, width) => {
38
+ if (!table || !width) {
39
+ return;
36
40
  }
37
- return dataAttrsInTable;
41
+ table.style.setProperty('width', `${width}px`);
38
42
  };
39
43
  const toDOM = (node, props) => {
40
44
  let colgroup = '';
41
45
  if (props.allowColumnResizing) {
42
46
  colgroup = ['colgroup', {}, ...generateColgroup(node)];
43
47
  }
44
- return ['table', tableAttributes(node, props.options, props.view.state, props.getPos()), colgroup, ['tbody', 0]];
48
+ return ['table', tableAttributes(node), colgroup, ['tbody', 0]];
45
49
  };
46
50
  export default class TableView extends ReactNodeView {
47
51
  constructor(props) {
@@ -56,8 +60,12 @@ export default class TableView extends ReactNodeView {
56
60
  }
57
61
  getContentDOM() {
58
62
  const rendered = DOMSerializer.renderSpec(document, toDOM(this.node, this.reactComponentProps));
63
+ const tableInlineWidth = getInlineWidth(this.node, this.reactComponentProps.options, this.reactComponentProps.view.state, this.reactComponentProps.getPos());
59
64
  if (rendered.dom) {
60
65
  this.table = rendered.dom;
66
+ if (tableInlineWidth) {
67
+ handleInlineTableWidth(this.table, tableInlineWidth);
68
+ }
61
69
  }
62
70
  return rendered;
63
71
  }
@@ -65,10 +73,16 @@ export default class TableView extends ReactNodeView {
65
73
  if (!this.table) {
66
74
  return;
67
75
  }
68
- const attrs = tableAttributes(node, this.reactComponentProps.options, this.view.state, this.getPos());
76
+ const attrs = tableAttributes(node);
69
77
  Object.keys(attrs).forEach(attr => {
70
78
  this.table.setAttribute(attr, attrs[attr]);
71
79
  });
80
+
81
+ // handle inline style when table been resized
82
+ const tableInlineWidth = getInlineWidth(node, this.reactComponentProps.options, this.view.state, this.getPos());
83
+ if (tableInlineWidth) {
84
+ handleInlineTableWidth(this.table, tableInlineWidth);
85
+ }
72
86
  }
73
87
  render(props, forwardRef) {
74
88
  // TODO: ED-15663
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "sideEffects": false
5
5
  }
@@ -6,12 +6,10 @@ import _get from "@babel/runtime/helpers/get";
6
6
  import _inherits from "@babel/runtime/helpers/inherits";
7
7
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
8
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
10
9
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
11
11
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
12
12
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
13
  import React from 'react';
16
14
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
17
15
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
@@ -27,33 +25,38 @@ import { generateColgroup } from '../pm-plugins/table-resizing/utils';
27
25
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
28
26
  import { isTableNested } from '../utils';
29
27
  import TableComponent from './TableComponent';
30
- var tableAttributes = function tableAttributes(node, options, state, pos) {
31
- // provide a width for tables when custom table width is supported
32
- // this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
33
- // support screen size adjustments
34
- var shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !isTableNested(state, pos);
35
- var style = "width: ".concat(node.attrs.isNumberColumnEnabled ? getTableContainerWidth(node) - akEditorTableNumberColumnWidth : getTableContainerWidth(node), "px");
36
- var dataAttrsInTable = {
28
+ var tableAttributes = function tableAttributes(node) {
29
+ return {
37
30
  'data-number-column': node.attrs.isNumberColumnEnabled,
38
31
  'data-layout': node.attrs.layout,
39
32
  'data-autosize': node.attrs.__autoSize,
40
33
  'data-table-local-id': node.attrs.localId || '',
41
34
  'data-table-width': node.attrs.width
42
35
  };
43
- if (shouldHaveInlineWidth) {
44
- // this should be fixed because style will overwrite any existing styles, current found conflict with sticky headers
45
- return _objectSpread(_objectSpread({}, dataAttrsInTable), {}, {
46
- style: style
47
- });
36
+ };
37
+ var getInlineWidth = function getInlineWidth(node, options, state, pos) {
38
+ // provide a width for tables when custom table width is supported
39
+ // this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
40
+ // support screen size adjustments
41
+ var shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !isTableNested(state, pos);
42
+ var widthValue = getTableContainerWidth(node);
43
+ if (node.attrs.isNumberColumnEnabled) {
44
+ widthValue -= akEditorTableNumberColumnWidth;
45
+ }
46
+ return shouldHaveInlineWidth ? widthValue : undefined;
47
+ };
48
+ var handleInlineTableWidth = function handleInlineTableWidth(table, width) {
49
+ if (!table || !width) {
50
+ return;
48
51
  }
49
- return dataAttrsInTable;
52
+ table.style.setProperty('width', "".concat(width, "px"));
50
53
  };
51
54
  var toDOM = function toDOM(node, props) {
52
55
  var colgroup = '';
53
56
  if (props.allowColumnResizing) {
54
57
  colgroup = ['colgroup', {}].concat(_toConsumableArray(generateColgroup(node)));
55
58
  }
56
- return ['table', tableAttributes(node, props.options, props.view.state, props.getPos()), colgroup, ['tbody', 0]];
59
+ return ['table', tableAttributes(node), colgroup, ['tbody', 0]];
57
60
  };
58
61
  var TableView = /*#__PURE__*/function (_ReactNodeView) {
59
62
  _inherits(TableView, _ReactNodeView);
@@ -75,8 +78,12 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
75
78
  key: "getContentDOM",
76
79
  value: function getContentDOM() {
77
80
  var rendered = DOMSerializer.renderSpec(document, toDOM(this.node, this.reactComponentProps));
81
+ var tableInlineWidth = getInlineWidth(this.node, this.reactComponentProps.options, this.reactComponentProps.view.state, this.reactComponentProps.getPos());
78
82
  if (rendered.dom) {
79
83
  this.table = rendered.dom;
84
+ if (tableInlineWidth) {
85
+ handleInlineTableWidth(this.table, tableInlineWidth);
86
+ }
80
87
  }
81
88
  return rendered;
82
89
  }
@@ -87,10 +94,16 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
87
94
  if (!this.table) {
88
95
  return;
89
96
  }
90
- var attrs = tableAttributes(node, this.reactComponentProps.options, this.view.state, this.getPos());
97
+ var attrs = tableAttributes(node);
91
98
  Object.keys(attrs).forEach(function (attr) {
92
99
  _this2.table.setAttribute(attr, attrs[attr]);
93
100
  });
101
+
102
+ // handle inline style when table been resized
103
+ var tableInlineWidth = getInlineWidth(node, this.reactComponentProps.options, this.view.state, this.getPos());
104
+ if (tableInlineWidth) {
105
+ handleInlineTableWidth(this.table, tableInlineWidth);
106
+ }
94
107
  }
95
108
  }, {
96
109
  key: "render",
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "sideEffects": false
5
5
  }
@@ -4,4 +4,4 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  export declare const pluginKey: PluginKey<any>;
5
5
  export declare const getDecorations: (state: EditorState) => DecorationSet;
6
6
  export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, decorationSet: DecorationSet, oldState: EditorState, newState: EditorState) => DecorationSet;
7
- export declare const createPlugin: () => SafePlugin<any>;
7
+ export declare const createPlugin: () => SafePlugin<DecorationSet>;
@@ -1,3 +1 @@
1
- /// <reference path="../../../../../../../../typings/prosemirror.d.ts" />
2
- /// <reference path="../../../../../../../../typings/prosemirror-state.d.ts" />
3
1
  export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: import("../types").TablePluginState | ((state: import("prosemirror-state").EditorState) => import("../types").TablePluginState)) => import("prosemirror-state").SafeStateField<import("../types").TablePluginState>, createCommand: <A = import("../types").TablePluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command, getPluginState: (state: import("prosemirror-state").EditorState) => import("../types").TablePluginState;
@@ -1,5 +1,3 @@
1
- /// <reference path="../../../../../../../../../typings/prosemirror.d.ts" />
2
- /// <reference path="../../../../../../../../../typings/prosemirror-state.d.ts" />
3
1
  import { StickyPluginAction, StickyPluginState } from './types';
4
2
  declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: StickyPluginState | ((state: import("prosemirror-state").EditorState) => StickyPluginState)) => import("prosemirror-state").SafeStateField<StickyPluginState>, createCommand: <A = StickyPluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
5
3
  export { createPluginState, createCommand };
@@ -1,5 +1,3 @@
1
- /// <reference path="../../../../../../../../../typings/prosemirror.d.ts" />
2
- /// <reference path="../../../../../../../../../typings/prosemirror-state.d.ts" />
3
1
  import { ColumnResizingPluginState } from '../../types';
4
2
  export declare const createCommand: <A = import("../../types").ColumnResizingPluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
5
3
  export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: ColumnResizingPluginState | ((state: import("prosemirror-state").EditorState) => ColumnResizingPluginState)) => import("prosemirror-state").SafeStateField<ColumnResizingPluginState>;
@@ -6,7 +6,7 @@ import { EditorView } from '@atlaskit/editor-prosemirror/view';
6
6
  import { TableOptions } from '../../../nodeviews/types';
7
7
  export declare function getLayoutSize(tableLayout: TableLayout, containerWidth: number | undefined, options: TableOptions): number;
8
8
  export declare function getDefaultLayoutMaxWidth(containerWidth?: number): number;
9
- export declare function pointsAtCell($pos: ResolvedPos): false | PMNode | null | undefined;
9
+ export declare function pointsAtCell($pos: ResolvedPos): false | PMNode | null;
10
10
  export declare function currentColWidth(view: EditorView, cellPos: number, { colspan, colwidth }: CellAttributes): number;
11
11
  export declare function domCellAround(target: HTMLElement | null): HTMLElement | null;
12
12
  interface getTableMaxWidthProps {
@@ -4,4 +4,4 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  export declare const pluginKey: PluginKey<any>;
5
5
  export declare const getDecorations: (state: EditorState) => DecorationSet;
6
6
  export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, decorationSet: DecorationSet, oldState: EditorState, newState: EditorState) => DecorationSet;
7
- export declare const createPlugin: () => SafePlugin<any>;
7
+ export declare const createPlugin: () => SafePlugin<DecorationSet>;
@@ -1,3 +1 @@
1
- /// <reference path="../../../../../../../../typings/prosemirror.d.ts" />
2
- /// <reference path="../../../../../../../../typings/prosemirror-state.d.ts" />
3
1
  export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: import("../types").TablePluginState | ((state: import("prosemirror-state").EditorState) => import("../types").TablePluginState)) => import("prosemirror-state").SafeStateField<import("../types").TablePluginState>, createCommand: <A = import("../types").TablePluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command, getPluginState: (state: import("prosemirror-state").EditorState) => import("../types").TablePluginState;
@@ -1,5 +1,3 @@
1
- /// <reference path="../../../../../../../../../typings/prosemirror.d.ts" />
2
- /// <reference path="../../../../../../../../../typings/prosemirror-state.d.ts" />
3
1
  import { StickyPluginAction, StickyPluginState } from './types';
4
2
  declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: StickyPluginState | ((state: import("prosemirror-state").EditorState) => StickyPluginState)) => import("prosemirror-state").SafeStateField<StickyPluginState>, createCommand: <A = StickyPluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
5
3
  export { createPluginState, createCommand };
@@ -1,5 +1,3 @@
1
- /// <reference path="../../../../../../../../../typings/prosemirror.d.ts" />
2
- /// <reference path="../../../../../../../../../typings/prosemirror-state.d.ts" />
3
1
  import { ColumnResizingPluginState } from '../../types';
4
2
  export declare const createCommand: <A = import("../../types").ColumnResizingPluginAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
5
3
  export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: ColumnResizingPluginState | ((state: import("prosemirror-state").EditorState) => ColumnResizingPluginState)) => import("prosemirror-state").SafeStateField<ColumnResizingPluginState>;
@@ -6,7 +6,7 @@ import { EditorView } from '@atlaskit/editor-prosemirror/view';
6
6
  import { TableOptions } from '../../../nodeviews/types';
7
7
  export declare function getLayoutSize(tableLayout: TableLayout, containerWidth: number | undefined, options: TableOptions): number;
8
8
  export declare function getDefaultLayoutMaxWidth(containerWidth?: number): number;
9
- export declare function pointsAtCell($pos: ResolvedPos): false | PMNode | null | undefined;
9
+ export declare function pointsAtCell($pos: ResolvedPos): false | PMNode | null;
10
10
  export declare function currentColWidth(view: EditorView, cellPos: number, { colspan, colwidth }: CellAttributes): number;
11
11
  export declare function domCellAround(target: HTMLElement | null): HTMLElement | null;
12
12
  interface getTableMaxWidthProps {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -27,12 +27,12 @@
27
27
  "releaseModel": "continuous"
28
28
  },
29
29
  "dependencies": {
30
- "@atlaskit/adf-schema": "^28.0.0",
30
+ "@atlaskit/adf-schema": "^28.1.0",
31
31
  "@atlaskit/editor-common": "^74.42.0",
32
32
  "@atlaskit/editor-palette": "1.5.1",
33
33
  "@atlaskit/editor-plugin-analytics": "^0.1.0",
34
- "@atlaskit/editor-plugin-content-insertion": "^0.0.7",
35
- "@atlaskit/editor-prosemirror": "1.0.2",
34
+ "@atlaskit/editor-plugin-content-insertion": "^0.0.8",
35
+ "@atlaskit/editor-prosemirror": "1.1.0",
36
36
  "@atlaskit/editor-shared-styles": "^2.6.0",
37
37
  "@atlaskit/editor-tables": "^2.3.0",
38
38
  "@atlaskit/icon": "^21.12.0",
@@ -36,41 +36,45 @@ import { Props, TableOptions } from './types';
36
36
 
37
37
  type ForwardRef = (node: HTMLElement | null) => void;
38
38
 
39
- const tableAttributes = (
39
+ const tableAttributes = (node: PmNode) => {
40
+ return {
41
+ 'data-number-column': node.attrs.isNumberColumnEnabled,
42
+ 'data-layout': node.attrs.layout,
43
+ 'data-autosize': node.attrs.__autoSize,
44
+ 'data-table-local-id': node.attrs.localId || '',
45
+ 'data-table-width': node.attrs.width,
46
+ };
47
+ };
48
+
49
+ const getInlineWidth = (
40
50
  node: PmNode,
41
51
  options: Props['options'],
42
52
  state: EditorState,
43
53
  pos: number | undefined,
44
- ) => {
54
+ ): number | undefined => {
45
55
  // provide a width for tables when custom table width is supported
46
56
  // this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
47
57
  // support screen size adjustments
48
58
  const shouldHaveInlineWidth =
49
59
  options?.isTableResizingEnabled && !isTableNested(state, pos);
50
60
 
51
- let style = `width: ${
52
- node.attrs.isNumberColumnEnabled
53
- ? getTableContainerWidth(node) - akEditorTableNumberColumnWidth
54
- : getTableContainerWidth(node)
55
- }px`;
61
+ let widthValue = getTableContainerWidth(node);
56
62
 
57
- const dataAttrsInTable = {
58
- 'data-number-column': node.attrs.isNumberColumnEnabled,
59
- 'data-layout': node.attrs.layout,
60
- 'data-autosize': node.attrs.__autoSize,
61
- 'data-table-local-id': node.attrs.localId || '',
62
- 'data-table-width': node.attrs.width,
63
- };
64
-
65
- if (shouldHaveInlineWidth) {
66
- // this should be fixed because style will overwrite any existing styles, current found conflict with sticky headers
67
- return {
68
- ...dataAttrsInTable,
69
- style,
70
- };
63
+ if (node.attrs.isNumberColumnEnabled) {
64
+ widthValue -= akEditorTableNumberColumnWidth;
71
65
  }
72
66
 
73
- return dataAttrsInTable;
67
+ return shouldHaveInlineWidth ? widthValue : undefined;
68
+ };
69
+
70
+ const handleInlineTableWidth = (
71
+ table: HTMLElement,
72
+ width: number | undefined,
73
+ ) => {
74
+ if (!table || !width) {
75
+ return;
76
+ }
77
+ table.style.setProperty('width', `${width}px`);
74
78
  };
75
79
 
76
80
  const toDOM = (node: PmNode, props: Props) => {
@@ -82,7 +86,7 @@ const toDOM = (node: PmNode, props: Props) => {
82
86
 
83
87
  return [
84
88
  'table',
85
- tableAttributes(node, props.options, props.view.state, props.getPos()),
89
+ tableAttributes(node),
86
90
  colgroup,
87
91
  ['tbody', 0],
88
92
  ] as DOMOutputSpec;
@@ -123,8 +127,18 @@ export default class TableView extends ReactNodeView<Props> {
123
127
  contentDOM?: HTMLElement;
124
128
  };
125
129
 
130
+ const tableInlineWidth = getInlineWidth(
131
+ this.node,
132
+ this.reactComponentProps.options,
133
+ this.reactComponentProps.view.state,
134
+ this.reactComponentProps.getPos(),
135
+ );
136
+
126
137
  if (rendered.dom) {
127
138
  this.table = rendered.dom;
139
+ if (tableInlineWidth) {
140
+ handleInlineTableWidth(this.table, tableInlineWidth);
141
+ }
128
142
  }
129
143
 
130
144
  return rendered;
@@ -135,15 +149,22 @@ export default class TableView extends ReactNodeView<Props> {
135
149
  return;
136
150
  }
137
151
 
138
- const attrs = tableAttributes(
152
+ const attrs = tableAttributes(node);
153
+ (Object.keys(attrs) as Array<keyof typeof attrs>).forEach((attr) => {
154
+ this.table!.setAttribute(attr, attrs[attr]);
155
+ });
156
+
157
+ // handle inline style when table been resized
158
+ const tableInlineWidth = getInlineWidth(
139
159
  node,
140
160
  (this.reactComponentProps as Props).options,
141
161
  this.view.state,
142
162
  this.getPos(),
143
163
  );
144
- (Object.keys(attrs) as Array<keyof typeof attrs>).forEach((attr) => {
145
- this.table!.setAttribute(attr, attrs[attr]);
146
- });
164
+
165
+ if (tableInlineWidth) {
166
+ handleInlineTableWidth(this.table, tableInlineWidth);
167
+ }
147
168
  }
148
169
 
149
170
  getNode = () => {