@atlaskit/editor-plugin-table 2.6.0 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +32 -22
- package/dist/cjs/plugins/table/nodeviews/table.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +9 -5
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +28 -18
- package/dist/es2019/plugins/table/nodeviews/table.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +9 -5
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +27 -17
- package/dist/esm/plugins/table/nodeviews/table.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +9 -5
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +1 -0
- package/package.json +2 -2
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +14 -14
- package/src/plugins/table/nodeviews/TableComponent.tsx +19 -1
- package/src/plugins/table/nodeviews/TableResizer.tsx +34 -22
- package/src/plugins/table/nodeviews/table.tsx +6 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +21 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 2.6.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`bc9f806f84a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/bc9f806f84a) - Toggle handle visibility of resizer if current table is selected
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 2.6.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`84516fbd72d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/84516fbd72d) - [ux] ED-19068: fix numbered columns scroll bar issue
|
|
15
|
+
|
|
3
16
|
## 2.6.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -25,6 +25,7 @@ var _commands = require("../commands");
|
|
|
25
25
|
var _pluginFactory = require("../pm-plugins/plugin-factory");
|
|
26
26
|
var _stickyHeaders = require("../pm-plugins/sticky-headers");
|
|
27
27
|
var _utils3 = require("../pm-plugins/table-resizing/utils");
|
|
28
|
+
var _colgroup = require("../pm-plugins/table-resizing/utils/colgroup");
|
|
28
29
|
var _dom = require("../pm-plugins/table-resizing/utils/dom");
|
|
29
30
|
var _types = require("../types");
|
|
30
31
|
var _TableFloatingControls = _interopRequireDefault(require("../ui/TableFloatingControls"));
|
|
@@ -140,9 +141,21 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
140
141
|
if (shouldScaleTable) {
|
|
141
142
|
_this.scaleTable({
|
|
142
143
|
parentWidth: parentWidth,
|
|
143
|
-
layoutChanged: layoutChanged
|
|
144
|
+
layoutChanged: layoutChanged,
|
|
145
|
+
isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
|
|
144
146
|
});
|
|
145
147
|
}
|
|
148
|
+
|
|
149
|
+
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
150
|
+
if (options !== null && options !== void 0 && options.isTableResizingEnabled && hasNumberedColumnChanged) {
|
|
151
|
+
if (!(0, _colgroup.hasTableBeenResized)(prevNode)) {
|
|
152
|
+
_this.scaleTable({
|
|
153
|
+
parentWidth: parentWidth,
|
|
154
|
+
layoutChanged: layoutChanged,
|
|
155
|
+
isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
146
159
|
_this.updateParentWidth(parentWidth);
|
|
147
160
|
}
|
|
148
161
|
_this.node = node;
|
|
@@ -14,10 +14,11 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
14
14
|
var _guideline = require("@atlaskit/editor-common/guideline");
|
|
15
15
|
var _resizer = require("@atlaskit/editor-common/resizer");
|
|
16
16
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
17
|
-
var _utils = require("
|
|
17
|
+
var _utils = require("@atlaskit/editor-tables/utils");
|
|
18
|
+
var _utils2 = require("../pm-plugins/table-resizing/utils");
|
|
18
19
|
var _tableWidth = require("../pm-plugins/table-width");
|
|
19
20
|
var _consts = require("../ui/consts");
|
|
20
|
-
var
|
|
21
|
+
var _utils3 = require("../utils");
|
|
21
22
|
var _guidelines = require("../utils/guidelines");
|
|
22
23
|
var _snapping = require("../utils/snapping");
|
|
23
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -39,25 +40,13 @@ var generateResizedPayload = function generateResizedPayload(props) {
|
|
|
39
40
|
newWidth: props.resizedNode.attrs.width,
|
|
40
41
|
prevWidth: (_props$originalNode$a = props.originalNode.attrs.width) !== null && _props$originalNode$a !== void 0 ? _props$originalNode$a : null,
|
|
41
42
|
nodeSize: props.resizedNode.nodeSize,
|
|
42
|
-
totalTableWidth: (0,
|
|
43
|
+
totalTableWidth: (0, _utils2.hasTableBeenResized)(props.resizedNode) ? (0, _utils3.getTableWidth)(props.resizedNode) : null,
|
|
43
44
|
totalRowCount: tableMap.height,
|
|
44
45
|
totalColumnCount: tableMap.width
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
};
|
|
48
|
-
var
|
|
49
|
-
var children = _ref.children,
|
|
50
|
-
width = _ref.width,
|
|
51
|
-
maxWidth = _ref.maxWidth,
|
|
52
|
-
updateWidth = _ref.updateWidth,
|
|
53
|
-
editorView = _ref.editorView,
|
|
54
|
-
getPos = _ref.getPos,
|
|
55
|
-
node = _ref.node,
|
|
56
|
-
tableRef = _ref.tableRef,
|
|
57
|
-
displayGuideline = _ref.displayGuideline,
|
|
58
|
-
attachAnalyticsEvent = _ref.attachAnalyticsEvent;
|
|
59
|
-
var currentColumnCount = (0, _utils.getColgroupChildrenLength)(node);
|
|
60
|
-
var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * _utils.COLUMN_MIN_WIDTH : 3 * _utils.COLUMN_MIN_WIDTH;
|
|
49
|
+
var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
|
|
61
50
|
var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
|
|
62
51
|
var handleHeightSize = 'small';
|
|
63
52
|
/*
|
|
@@ -73,11 +62,32 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
73
62
|
} else if (tableHeight && tableHeight >= 96) {
|
|
74
63
|
handleHeightSize = 'large';
|
|
75
64
|
}
|
|
65
|
+
return handleHeightSize;
|
|
66
|
+
};
|
|
67
|
+
var getResizerMinWidth = function getResizerMinWidth(node) {
|
|
68
|
+
var currentColumnCount = (0, _utils2.getColgroupChildrenLength)(node);
|
|
69
|
+
var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * _utils2.COLUMN_MIN_WIDTH : 3 * _utils2.COLUMN_MIN_WIDTH;
|
|
70
|
+
return minColumnWidth;
|
|
71
|
+
};
|
|
72
|
+
var TableResizer = function TableResizer(_ref) {
|
|
73
|
+
var _findTable, _editorView$state;
|
|
74
|
+
var children = _ref.children,
|
|
75
|
+
width = _ref.width,
|
|
76
|
+
maxWidth = _ref.maxWidth,
|
|
77
|
+
updateWidth = _ref.updateWidth,
|
|
78
|
+
editorView = _ref.editorView,
|
|
79
|
+
getPos = _ref.getPos,
|
|
80
|
+
node = _ref.node,
|
|
81
|
+
tableRef = _ref.tableRef,
|
|
82
|
+
displayGuideline = _ref.displayGuideline,
|
|
83
|
+
attachAnalyticsEvent = _ref.attachAnalyticsEvent;
|
|
76
84
|
var currentGap = (0, _react.useRef)(0);
|
|
77
85
|
var _useState = (0, _react.useState)(false),
|
|
78
86
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
79
87
|
snappingEnabled = _useState2[0],
|
|
80
88
|
setSnappingEnabled = _useState2[1];
|
|
89
|
+
var resizerMinWidth = getResizerMinWidth(node);
|
|
90
|
+
var handleHeightSize = getResizerHandleHeight(tableRef);
|
|
81
91
|
var updateActiveGuidelines = (0, _react.useCallback)(function (_ref2) {
|
|
82
92
|
var gap = _ref2.gap,
|
|
83
93
|
keys = _ref2.keys;
|
|
@@ -98,8 +108,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
98
108
|
resizing: true
|
|
99
109
|
}));
|
|
100
110
|
setSnappingEnabled(displayGuideline(_guidelines.defaultGuidelines));
|
|
101
|
-
|
|
102
|
-
}, [width, displayGuideline, editorView]);
|
|
111
|
+
}, [displayGuideline, editorView]);
|
|
103
112
|
var handleResizeStop = (0, _react.useCallback)(function (originalState, delta) {
|
|
104
113
|
var newWidth = originalState.width + delta.width;
|
|
105
114
|
var state = editorView.state,
|
|
@@ -114,7 +123,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
114
123
|
width: newWidth
|
|
115
124
|
}));
|
|
116
125
|
var newNode = tr.doc.nodeAt(pos);
|
|
117
|
-
tr = (0,
|
|
126
|
+
tr = (0, _utils2.scaleTable)(tableRef, {
|
|
118
127
|
node: newNode,
|
|
119
128
|
prevNode: node,
|
|
120
129
|
start: pos + 1,
|
|
@@ -139,7 +148,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
139
148
|
if (typeof pos !== 'number') {
|
|
140
149
|
return;
|
|
141
150
|
}
|
|
142
|
-
(0,
|
|
151
|
+
(0, _utils2.previewScaleTable)(tableRef, {
|
|
143
152
|
node: node,
|
|
144
153
|
prevNode: node,
|
|
145
154
|
start: pos + 1,
|
|
@@ -162,11 +171,12 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
162
171
|
handleResize: scheduleResize,
|
|
163
172
|
handleResizeStop: handleResizeStop,
|
|
164
173
|
resizeRatio: 2,
|
|
165
|
-
minWidth:
|
|
174
|
+
minWidth: resizerMinWidth,
|
|
166
175
|
maxWidth: maxWidth,
|
|
167
176
|
snapGap: _consts.TABLE_SNAP_GAP,
|
|
168
177
|
snap: guidelineSnaps,
|
|
169
|
-
handlePositioning: "adjacent"
|
|
178
|
+
handlePositioning: "adjacent",
|
|
179
|
+
isHandleVisible: ((_findTable = (0, _utils.findTable)((_editorView$state = editorView.state) === null || _editorView$state === void 0 ? void 0 : _editorView$state.selection)) === null || _findTable === void 0 ? void 0 : _findTable.pos) === getPos()
|
|
170
180
|
}, children);
|
|
171
181
|
};
|
|
172
182
|
exports.TableResizer = TableResizer;
|
|
@@ -20,6 +20,7 @@ var _prosemirrorModel = require("prosemirror-model");
|
|
|
20
20
|
var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
21
21
|
var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
|
|
22
22
|
var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
|
|
23
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
23
24
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
24
25
|
var _createPluginConfig = require("../create-plugin-config");
|
|
25
26
|
var _pluginFactory = require("../pm-plugins/plugin-factory");
|
|
@@ -36,7 +37,7 @@ var tableAttributes = function tableAttributes(node, options, state, pos) {
|
|
|
36
37
|
// this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
|
|
37
38
|
// support screen size adjustments
|
|
38
39
|
var shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !(0, _utils2.isTableNested)(state, pos);
|
|
39
|
-
var style = shouldHaveInlineWidth ? "width: ".concat((0, _nodeWidth.getTableContainerWidth)(node), "px") : undefined;
|
|
40
|
+
var style = shouldHaveInlineWidth ? "width: ".concat(node.attrs.isNumberColumnEnabled ? (0, _nodeWidth.getTableContainerWidth)(node) - _editorSharedStyles.akEditorTableNumberColumnWidth : (0, _nodeWidth.getTableContainerWidth)(node), "px") : undefined;
|
|
40
41
|
return {
|
|
41
42
|
'data-number-column': node.attrs.isNumberColumnEnabled,
|
|
42
43
|
'data-layout': node.attrs.layout,
|
|
@@ -8,6 +8,7 @@ exports.scaleTable = exports.scale = exports.previewScaleTable = void 0;
|
|
|
8
8
|
exports.scaleTableTo = scaleTableTo;
|
|
9
9
|
exports.scaleWithParent = void 0;
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
11
12
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
12
13
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
13
14
|
var _transforms = require("../../../transforms");
|
|
@@ -32,12 +33,13 @@ var scale = function scale(tableRef, options, domAtPos) {
|
|
|
32
33
|
prevNode = options.prevNode,
|
|
33
34
|
start = options.start,
|
|
34
35
|
isBreakoutEnabled = options.isBreakoutEnabled,
|
|
35
|
-
layoutChanged = options.layoutChanged
|
|
36
|
-
|
|
36
|
+
layoutChanged = options.layoutChanged,
|
|
37
|
+
isTableResizingEnabled = options.isTableResizingEnabled;
|
|
38
|
+
var maxSize = isTableResizingEnabled ? (0, _nodeWidth.getTableContainerWidth)(node) : (0, _misc.getLayoutSize)(node.attrs.layout, containerWidth, {
|
|
37
39
|
isBreakoutEnabled: isBreakoutEnabled
|
|
38
40
|
});
|
|
39
41
|
var prevTableWidth = (0, _utils.getTableWidth)(prevNode);
|
|
40
|
-
var previousMaxSize = (0, _misc.getLayoutSize)(prevNode.attrs.layout, previousContainerWidth, {
|
|
42
|
+
var previousMaxSize = isTableResizingEnabled ? (0, _nodeWidth.getTableContainerWidth)(node) : (0, _misc.getLayoutSize)(prevNode.attrs.layout, previousContainerWidth, {
|
|
41
43
|
isBreakoutEnabled: isBreakoutEnabled
|
|
42
44
|
});
|
|
43
45
|
var newWidth = maxSize;
|
|
@@ -116,7 +118,9 @@ var previewScaleTable = function previewScaleTable(tableRef, options, domAtPos)
|
|
|
116
118
|
return;
|
|
117
119
|
}
|
|
118
120
|
if (parentWidth) {
|
|
119
|
-
|
|
121
|
+
var isNumberColumnEnabled = node.attrs.isNumberColumnEnabled;
|
|
122
|
+
var width = isNumberColumnEnabled ? parentWidth - _editorSharedStyles.akEditorTableNumberColumnWidth : parentWidth;
|
|
123
|
+
tableRef.style.width = "".concat(width, "px");
|
|
120
124
|
}
|
|
121
125
|
if (!(0, _colgroup.hasTableBeenResized)(node)) {
|
|
122
126
|
return;
|
|
@@ -138,12 +142,12 @@ var scaleTable = function scaleTable(tableRef, options, domAtPos) {
|
|
|
138
142
|
start = options.start,
|
|
139
143
|
parentWidth = options.parentWidth,
|
|
140
144
|
layoutChanged = options.layoutChanged;
|
|
141
|
-
|
|
142
145
|
// If a table has not been resized yet, columns should be auto.
|
|
143
146
|
if ((0, _colgroup.hasTableBeenResized)(node) === false) {
|
|
144
147
|
// If its not a re-sized table, we still want to re-create cols
|
|
145
148
|
// To force reflow of columns upon delete.
|
|
146
149
|
(0, _colgroup.insertColgroupFromNode)(tableRef, node);
|
|
150
|
+
tr.setMeta('scrollIntoView', false);
|
|
147
151
|
return tr;
|
|
148
152
|
}
|
|
149
153
|
var resizeState;
|
package/dist/cjs/version.json
CHANGED
|
@@ -12,6 +12,7 @@ import { autoSizeTable, clearHoverSelection } from '../commands';
|
|
|
12
12
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
13
13
|
import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
|
|
14
14
|
import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scaleTable } from '../pm-plugins/table-resizing/utils';
|
|
15
|
+
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
15
16
|
import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
|
|
16
17
|
import { TableCssClassName as ClassName, ShadowEvent } from '../types';
|
|
17
18
|
import TableFloatingControls from '../ui/TableFloatingControls';
|
|
@@ -125,9 +126,21 @@ class TableComponent extends React.Component {
|
|
|
125
126
|
if (shouldScaleTable) {
|
|
126
127
|
this.scaleTable({
|
|
127
128
|
parentWidth,
|
|
128
|
-
layoutChanged
|
|
129
|
+
layoutChanged,
|
|
130
|
+
isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
|
|
129
131
|
});
|
|
130
132
|
}
|
|
133
|
+
|
|
134
|
+
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
135
|
+
if (options !== null && options !== void 0 && options.isTableResizingEnabled && hasNumberedColumnChanged) {
|
|
136
|
+
if (!hasTableBeenResized(prevNode)) {
|
|
137
|
+
this.scaleTable({
|
|
138
|
+
parentWidth,
|
|
139
|
+
layoutChanged,
|
|
140
|
+
isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
131
144
|
this.updateParentWidth(parentWidth);
|
|
132
145
|
}
|
|
133
146
|
this.node = node;
|
|
@@ -4,6 +4,7 @@ import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-commo
|
|
|
4
4
|
import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
|
|
5
5
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
6
6
|
import { TableMap } from '@atlaskit/editor-tables';
|
|
7
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
7
8
|
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, hasTableBeenResized, previewScaleTable, scaleTable } from '../pm-plugins/table-resizing/utils';
|
|
8
9
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
9
10
|
import { TABLE_HIGHLIGHT_GAP, TABLE_SNAP_GAP } from '../ui/consts';
|
|
@@ -31,20 +32,7 @@ const generateResizedPayload = props => {
|
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
|
-
|
|
35
|
-
children,
|
|
36
|
-
width,
|
|
37
|
-
maxWidth,
|
|
38
|
-
updateWidth,
|
|
39
|
-
editorView,
|
|
40
|
-
getPos,
|
|
41
|
-
node,
|
|
42
|
-
tableRef,
|
|
43
|
-
displayGuideline,
|
|
44
|
-
attachAnalyticsEvent
|
|
45
|
-
}) => {
|
|
46
|
-
const currentColumnCount = getColgroupChildrenLength(node);
|
|
47
|
-
const minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
|
|
35
|
+
const getResizerHandleHeight = tableRef => {
|
|
48
36
|
const tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
|
|
49
37
|
let handleHeightSize = 'small';
|
|
50
38
|
/*
|
|
@@ -60,8 +48,30 @@ export const TableResizer = ({
|
|
|
60
48
|
} else if (tableHeight && tableHeight >= 96) {
|
|
61
49
|
handleHeightSize = 'large';
|
|
62
50
|
}
|
|
51
|
+
return handleHeightSize;
|
|
52
|
+
};
|
|
53
|
+
const getResizerMinWidth = node => {
|
|
54
|
+
const currentColumnCount = getColgroupChildrenLength(node);
|
|
55
|
+
const minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
|
|
56
|
+
return minColumnWidth;
|
|
57
|
+
};
|
|
58
|
+
export const TableResizer = ({
|
|
59
|
+
children,
|
|
60
|
+
width,
|
|
61
|
+
maxWidth,
|
|
62
|
+
updateWidth,
|
|
63
|
+
editorView,
|
|
64
|
+
getPos,
|
|
65
|
+
node,
|
|
66
|
+
tableRef,
|
|
67
|
+
displayGuideline,
|
|
68
|
+
attachAnalyticsEvent
|
|
69
|
+
}) => {
|
|
70
|
+
var _findTable, _editorView$state;
|
|
63
71
|
const currentGap = useRef(0);
|
|
64
72
|
const [snappingEnabled, setSnappingEnabled] = useState(false);
|
|
73
|
+
const resizerMinWidth = getResizerMinWidth(node);
|
|
74
|
+
const handleHeightSize = getResizerHandleHeight(tableRef);
|
|
65
75
|
const updateActiveGuidelines = useCallback(({
|
|
66
76
|
gap,
|
|
67
77
|
keys
|
|
@@ -85,8 +95,7 @@ export const TableResizer = ({
|
|
|
85
95
|
resizing: true
|
|
86
96
|
}));
|
|
87
97
|
setSnappingEnabled(displayGuideline(defaultGuidelines));
|
|
88
|
-
|
|
89
|
-
}, [width, displayGuideline, editorView]);
|
|
98
|
+
}, [displayGuideline, editorView]);
|
|
90
99
|
const handleResizeStop = useCallback((originalState, delta) => {
|
|
91
100
|
const newWidth = originalState.width + delta.width;
|
|
92
101
|
const {
|
|
@@ -150,10 +159,11 @@ export const TableResizer = ({
|
|
|
150
159
|
handleResize: scheduleResize,
|
|
151
160
|
handleResizeStop: handleResizeStop,
|
|
152
161
|
resizeRatio: 2,
|
|
153
|
-
minWidth:
|
|
162
|
+
minWidth: resizerMinWidth,
|
|
154
163
|
maxWidth: maxWidth,
|
|
155
164
|
snapGap: TABLE_SNAP_GAP,
|
|
156
165
|
snap: guidelineSnaps,
|
|
157
|
-
handlePositioning: "adjacent"
|
|
166
|
+
handlePositioning: "adjacent",
|
|
167
|
+
isHandleVisible: ((_findTable = findTable((_editorView$state = editorView.state) === null || _editorView$state === void 0 ? void 0 : _editorView$state.selection)) === null || _findTable === void 0 ? void 0 : _findTable.pos) === getPos()
|
|
158
168
|
}, children);
|
|
159
169
|
};
|
|
@@ -4,6 +4,7 @@ import { DOMSerializer } from 'prosemirror-model';
|
|
|
4
4
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
5
5
|
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
6
6
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
7
|
+
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
7
8
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
8
9
|
import { pluginConfig as getPluginConfig } from '../create-plugin-config';
|
|
9
10
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
@@ -18,7 +19,7 @@ const tableAttributes = (node, options, state, pos) => {
|
|
|
18
19
|
// this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
|
|
19
20
|
// support screen size adjustments
|
|
20
21
|
const shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !isTableNested(state, pos);
|
|
21
|
-
let style = shouldHaveInlineWidth ? `width: ${getTableContainerWidth(node)}px` : undefined;
|
|
22
|
+
let style = shouldHaveInlineWidth ? `width: ${node.attrs.isNumberColumnEnabled ? getTableContainerWidth(node) - akEditorTableNumberColumnWidth : getTableContainerWidth(node)}px` : undefined;
|
|
22
23
|
return {
|
|
23
24
|
'data-number-column': node.attrs.isNumberColumnEnabled,
|
|
24
25
|
'data-layout': node.attrs.layout,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
1
2
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
3
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
3
4
|
import { updateColumnWidths } from '../../../transforms';
|
|
@@ -21,13 +22,14 @@ export const scale = (tableRef, options, domAtPos) => {
|
|
|
21
22
|
prevNode,
|
|
22
23
|
start,
|
|
23
24
|
isBreakoutEnabled,
|
|
24
|
-
layoutChanged
|
|
25
|
+
layoutChanged,
|
|
26
|
+
isTableResizingEnabled
|
|
25
27
|
} = options;
|
|
26
|
-
const maxSize = getLayoutSize(node.attrs.layout, containerWidth, {
|
|
28
|
+
const maxSize = isTableResizingEnabled ? getTableContainerWidth(node) : getLayoutSize(node.attrs.layout, containerWidth, {
|
|
27
29
|
isBreakoutEnabled
|
|
28
30
|
});
|
|
29
31
|
const prevTableWidth = getTableWidth(prevNode);
|
|
30
|
-
const previousMaxSize = getLayoutSize(prevNode.attrs.layout, previousContainerWidth, {
|
|
32
|
+
const previousMaxSize = isTableResizingEnabled ? getTableContainerWidth(node) : getLayoutSize(prevNode.attrs.layout, previousContainerWidth, {
|
|
31
33
|
isBreakoutEnabled
|
|
32
34
|
});
|
|
33
35
|
let newWidth = maxSize;
|
|
@@ -110,7 +112,9 @@ export const previewScaleTable = (tableRef, options, domAtPos) => {
|
|
|
110
112
|
return;
|
|
111
113
|
}
|
|
112
114
|
if (parentWidth) {
|
|
113
|
-
|
|
115
|
+
const isNumberColumnEnabled = node.attrs.isNumberColumnEnabled;
|
|
116
|
+
const width = isNumberColumnEnabled ? parentWidth - akEditorTableNumberColumnWidth : parentWidth;
|
|
117
|
+
tableRef.style.width = `${width}px`;
|
|
114
118
|
}
|
|
115
119
|
if (!hasTableBeenResized(node)) {
|
|
116
120
|
return;
|
|
@@ -132,12 +136,12 @@ export const scaleTable = (tableRef, options, domAtPos) => tr => {
|
|
|
132
136
|
parentWidth,
|
|
133
137
|
layoutChanged
|
|
134
138
|
} = options;
|
|
135
|
-
|
|
136
139
|
// If a table has not been resized yet, columns should be auto.
|
|
137
140
|
if (hasTableBeenResized(node) === false) {
|
|
138
141
|
// If its not a re-sized table, we still want to re-create cols
|
|
139
142
|
// To force reflow of columns upon delete.
|
|
140
143
|
insertColgroupFromNode(tableRef, node);
|
|
144
|
+
tr.setMeta('scrollIntoView', false);
|
|
141
145
|
return tr;
|
|
142
146
|
}
|
|
143
147
|
let resizeState;
|
package/dist/es2019/version.json
CHANGED
|
@@ -22,6 +22,7 @@ import { autoSizeTable, clearHoverSelection } from '../commands';
|
|
|
22
22
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
23
23
|
import { findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from '../pm-plugins/sticky-headers';
|
|
24
24
|
import { getLayoutSize, insertColgroupFromNode as recreateResizeColsByNode, scaleTable } from '../pm-plugins/table-resizing/utils';
|
|
25
|
+
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
25
26
|
import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
|
|
26
27
|
import { TableCssClassName as ClassName, ShadowEvent } from '../types';
|
|
27
28
|
import TableFloatingControls from '../ui/TableFloatingControls';
|
|
@@ -133,9 +134,21 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
133
134
|
if (shouldScaleTable) {
|
|
134
135
|
_this.scaleTable({
|
|
135
136
|
parentWidth: parentWidth,
|
|
136
|
-
layoutChanged: layoutChanged
|
|
137
|
+
layoutChanged: layoutChanged,
|
|
138
|
+
isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
|
|
137
139
|
});
|
|
138
140
|
}
|
|
141
|
+
|
|
142
|
+
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
143
|
+
if (options !== null && options !== void 0 && options.isTableResizingEnabled && hasNumberedColumnChanged) {
|
|
144
|
+
if (!hasTableBeenResized(prevNode)) {
|
|
145
|
+
_this.scaleTable({
|
|
146
|
+
parentWidth: parentWidth,
|
|
147
|
+
layoutChanged: layoutChanged,
|
|
148
|
+
isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
139
152
|
_this.updateParentWidth(parentWidth);
|
|
140
153
|
}
|
|
141
154
|
_this.node = node;
|
|
@@ -8,6 +8,7 @@ import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-commo
|
|
|
8
8
|
import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
|
|
9
9
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
10
10
|
import { TableMap } from '@atlaskit/editor-tables';
|
|
11
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
11
12
|
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, hasTableBeenResized, previewScaleTable, scaleTable } from '../pm-plugins/table-resizing/utils';
|
|
12
13
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
13
14
|
import { TABLE_HIGHLIGHT_GAP, TABLE_SNAP_GAP } from '../ui/consts';
|
|
@@ -35,19 +36,7 @@ var generateResizedPayload = function generateResizedPayload(props) {
|
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
};
|
|
38
|
-
|
|
39
|
-
var children = _ref.children,
|
|
40
|
-
width = _ref.width,
|
|
41
|
-
maxWidth = _ref.maxWidth,
|
|
42
|
-
updateWidth = _ref.updateWidth,
|
|
43
|
-
editorView = _ref.editorView,
|
|
44
|
-
getPos = _ref.getPos,
|
|
45
|
-
node = _ref.node,
|
|
46
|
-
tableRef = _ref.tableRef,
|
|
47
|
-
displayGuideline = _ref.displayGuideline,
|
|
48
|
-
attachAnalyticsEvent = _ref.attachAnalyticsEvent;
|
|
49
|
-
var currentColumnCount = getColgroupChildrenLength(node);
|
|
50
|
-
var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
|
|
39
|
+
var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
|
|
51
40
|
var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
|
|
52
41
|
var handleHeightSize = 'small';
|
|
53
42
|
/*
|
|
@@ -63,11 +52,32 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
63
52
|
} else if (tableHeight && tableHeight >= 96) {
|
|
64
53
|
handleHeightSize = 'large';
|
|
65
54
|
}
|
|
55
|
+
return handleHeightSize;
|
|
56
|
+
};
|
|
57
|
+
var getResizerMinWidth = function getResizerMinWidth(node) {
|
|
58
|
+
var currentColumnCount = getColgroupChildrenLength(node);
|
|
59
|
+
var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
|
|
60
|
+
return minColumnWidth;
|
|
61
|
+
};
|
|
62
|
+
export var TableResizer = function TableResizer(_ref) {
|
|
63
|
+
var _findTable, _editorView$state;
|
|
64
|
+
var children = _ref.children,
|
|
65
|
+
width = _ref.width,
|
|
66
|
+
maxWidth = _ref.maxWidth,
|
|
67
|
+
updateWidth = _ref.updateWidth,
|
|
68
|
+
editorView = _ref.editorView,
|
|
69
|
+
getPos = _ref.getPos,
|
|
70
|
+
node = _ref.node,
|
|
71
|
+
tableRef = _ref.tableRef,
|
|
72
|
+
displayGuideline = _ref.displayGuideline,
|
|
73
|
+
attachAnalyticsEvent = _ref.attachAnalyticsEvent;
|
|
66
74
|
var currentGap = useRef(0);
|
|
67
75
|
var _useState = useState(false),
|
|
68
76
|
_useState2 = _slicedToArray(_useState, 2),
|
|
69
77
|
snappingEnabled = _useState2[0],
|
|
70
78
|
setSnappingEnabled = _useState2[1];
|
|
79
|
+
var resizerMinWidth = getResizerMinWidth(node);
|
|
80
|
+
var handleHeightSize = getResizerHandleHeight(tableRef);
|
|
71
81
|
var updateActiveGuidelines = useCallback(function (_ref2) {
|
|
72
82
|
var gap = _ref2.gap,
|
|
73
83
|
keys = _ref2.keys;
|
|
@@ -88,8 +98,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
88
98
|
resizing: true
|
|
89
99
|
}));
|
|
90
100
|
setSnappingEnabled(displayGuideline(defaultGuidelines));
|
|
91
|
-
|
|
92
|
-
}, [width, displayGuideline, editorView]);
|
|
101
|
+
}, [displayGuideline, editorView]);
|
|
93
102
|
var handleResizeStop = useCallback(function (originalState, delta) {
|
|
94
103
|
var newWidth = originalState.width + delta.width;
|
|
95
104
|
var state = editorView.state,
|
|
@@ -152,10 +161,11 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
152
161
|
handleResize: scheduleResize,
|
|
153
162
|
handleResizeStop: handleResizeStop,
|
|
154
163
|
resizeRatio: 2,
|
|
155
|
-
minWidth:
|
|
164
|
+
minWidth: resizerMinWidth,
|
|
156
165
|
maxWidth: maxWidth,
|
|
157
166
|
snapGap: TABLE_SNAP_GAP,
|
|
158
167
|
snap: guidelineSnaps,
|
|
159
|
-
handlePositioning: "adjacent"
|
|
168
|
+
handlePositioning: "adjacent",
|
|
169
|
+
isHandleVisible: ((_findTable = findTable((_editorView$state = editorView.state) === null || _editorView$state === void 0 ? void 0 : _editorView$state.selection)) === null || _findTable === void 0 ? void 0 : _findTable.pos) === getPos()
|
|
160
170
|
}, children);
|
|
161
171
|
};
|
|
@@ -15,6 +15,7 @@ import { DOMSerializer } from 'prosemirror-model';
|
|
|
15
15
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
16
16
|
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
17
17
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
18
|
+
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
18
19
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
19
20
|
import { pluginConfig as getPluginConfig } from '../create-plugin-config';
|
|
20
21
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
@@ -29,7 +30,7 @@ var tableAttributes = function tableAttributes(node, options, state, pos) {
|
|
|
29
30
|
// this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
|
|
30
31
|
// support screen size adjustments
|
|
31
32
|
var shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !isTableNested(state, pos);
|
|
32
|
-
var style = shouldHaveInlineWidth ? "width: ".concat(getTableContainerWidth(node), "px") : undefined;
|
|
33
|
+
var style = shouldHaveInlineWidth ? "width: ".concat(node.attrs.isNumberColumnEnabled ? getTableContainerWidth(node) - akEditorTableNumberColumnWidth : getTableContainerWidth(node), "px") : undefined;
|
|
33
34
|
return {
|
|
34
35
|
'data-number-column': node.attrs.isNumberColumnEnabled,
|
|
35
36
|
'data-layout': node.attrs.layout,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
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; }
|
|
3
3
|
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; }
|
|
4
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
4
5
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
5
6
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
6
7
|
import { updateColumnWidths } from '../../../transforms';
|
|
@@ -23,12 +24,13 @@ export var scale = function scale(tableRef, options, domAtPos) {
|
|
|
23
24
|
prevNode = options.prevNode,
|
|
24
25
|
start = options.start,
|
|
25
26
|
isBreakoutEnabled = options.isBreakoutEnabled,
|
|
26
|
-
layoutChanged = options.layoutChanged
|
|
27
|
-
|
|
27
|
+
layoutChanged = options.layoutChanged,
|
|
28
|
+
isTableResizingEnabled = options.isTableResizingEnabled;
|
|
29
|
+
var maxSize = isTableResizingEnabled ? getTableContainerWidth(node) : getLayoutSize(node.attrs.layout, containerWidth, {
|
|
28
30
|
isBreakoutEnabled: isBreakoutEnabled
|
|
29
31
|
});
|
|
30
32
|
var prevTableWidth = getTableWidth(prevNode);
|
|
31
|
-
var previousMaxSize = getLayoutSize(prevNode.attrs.layout, previousContainerWidth, {
|
|
33
|
+
var previousMaxSize = isTableResizingEnabled ? getTableContainerWidth(node) : getLayoutSize(prevNode.attrs.layout, previousContainerWidth, {
|
|
32
34
|
isBreakoutEnabled: isBreakoutEnabled
|
|
33
35
|
});
|
|
34
36
|
var newWidth = maxSize;
|
|
@@ -105,7 +107,9 @@ export var previewScaleTable = function previewScaleTable(tableRef, options, dom
|
|
|
105
107
|
return;
|
|
106
108
|
}
|
|
107
109
|
if (parentWidth) {
|
|
108
|
-
|
|
110
|
+
var isNumberColumnEnabled = node.attrs.isNumberColumnEnabled;
|
|
111
|
+
var width = isNumberColumnEnabled ? parentWidth - akEditorTableNumberColumnWidth : parentWidth;
|
|
112
|
+
tableRef.style.width = "".concat(width, "px");
|
|
109
113
|
}
|
|
110
114
|
if (!hasTableBeenResized(node)) {
|
|
111
115
|
return;
|
|
@@ -126,12 +130,12 @@ export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
|
|
|
126
130
|
start = options.start,
|
|
127
131
|
parentWidth = options.parentWidth,
|
|
128
132
|
layoutChanged = options.layoutChanged;
|
|
129
|
-
|
|
130
133
|
// If a table has not been resized yet, columns should be auto.
|
|
131
134
|
if (hasTableBeenResized(node) === false) {
|
|
132
135
|
// If its not a re-sized table, we still want to re-create cols
|
|
133
136
|
// To force reflow of columns upon delete.
|
|
134
137
|
insertColgroupFromNode(tableRef, node);
|
|
138
|
+
tr.setMeta('scrollIntoView', false);
|
|
135
139
|
return tr;
|
|
136
140
|
}
|
|
137
141
|
var resizeState;
|
package/dist/esm/version.json
CHANGED
|
@@ -12,6 +12,7 @@ export interface ScaleOptions {
|
|
|
12
12
|
layoutChanged?: boolean;
|
|
13
13
|
isBreakoutEnabled?: boolean;
|
|
14
14
|
isFullWidthModeEnabled?: boolean;
|
|
15
|
+
isTableResizingEnabled?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export declare const scale: (tableRef: HTMLTableElement, options: ScaleOptions, domAtPos: DomAtPos) => ResizeState | undefined;
|
|
17
18
|
export declare const scaleWithParent: (tableRef: HTMLTableElement, parentWidth: number, table: PMNode, start: number, domAtPos: DomAtPos) => ResizeState;
|
|
@@ -12,6 +12,7 @@ export interface ScaleOptions {
|
|
|
12
12
|
layoutChanged?: boolean;
|
|
13
13
|
isBreakoutEnabled?: boolean;
|
|
14
14
|
isFullWidthModeEnabled?: boolean;
|
|
15
|
+
isTableResizingEnabled?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export declare const scale: (tableRef: HTMLTableElement, options: ScaleOptions, domAtPos: DomAtPos) => ResizeState | undefined;
|
|
17
18
|
export declare const scaleWithParent: (tableRef: HTMLTableElement, parentWidth: number, table: PMNode, start: number, domAtPos: DomAtPos) => ResizeState;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/adf-schema": "^26.3.0",
|
|
31
|
-
"@atlaskit/editor-common": "^74.
|
|
31
|
+
"@atlaskit/editor-common": "^74.28.0",
|
|
32
32
|
"@atlaskit/editor-palette": "1.5.1",
|
|
33
33
|
"@atlaskit/editor-plugin-analytics": "^0.1.0",
|
|
34
34
|
"@atlaskit/editor-plugin-content-insertion": "^0.0.6",
|
|
@@ -53,15 +53,15 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
53
53
|
);
|
|
54
54
|
const resolvedTable = findTable(editorView.state.selection);
|
|
55
55
|
|
|
56
|
-
return {
|
|
56
|
+
return { table: resolvedTable!.node, editorView };
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
describe('show correct container
|
|
59
|
+
describe('show correct table container', () => {
|
|
60
60
|
const buildContainer = (
|
|
61
61
|
isTableResizingEnabled: boolean,
|
|
62
62
|
isBreakoutEnabled: boolean = true,
|
|
63
63
|
) => {
|
|
64
|
-
const {
|
|
64
|
+
const { table, editorView } = createNode();
|
|
65
65
|
|
|
66
66
|
const { container } = render(
|
|
67
67
|
<TableContainer
|
|
@@ -69,7 +69,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
69
69
|
width: 1800,
|
|
70
70
|
lineLength: 720,
|
|
71
71
|
}}
|
|
72
|
-
node={
|
|
72
|
+
node={table}
|
|
73
73
|
isTableResizingEnabled={isTableResizingEnabled}
|
|
74
74
|
isBreakoutEnabled={isBreakoutEnabled}
|
|
75
75
|
className={''}
|
|
@@ -83,12 +83,12 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
83
83
|
return container;
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
-
test('when isTableResizingEnabled is true', () => {
|
|
86
|
+
test('should wrap table in resizer when isTableResizingEnabled is true', () => {
|
|
87
87
|
const container = buildContainer(true);
|
|
88
88
|
expect(!!container.querySelector('.resizer-item')).toBeTruthy();
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
test('when isTableResizingEnabled is false', () => {
|
|
91
|
+
test('should not wrap table in resizer when isTableResizingEnabled is false', () => {
|
|
92
92
|
const container = buildContainer(false);
|
|
93
93
|
expect(!!container.querySelector('.resizer-item')).toBeFalsy();
|
|
94
94
|
});
|
|
@@ -99,7 +99,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
99
99
|
isTableResizingEnabled: boolean,
|
|
100
100
|
isBreakoutEnabled: boolean = true,
|
|
101
101
|
) => {
|
|
102
|
-
const {
|
|
102
|
+
const { table, editorView } = createNode();
|
|
103
103
|
|
|
104
104
|
const { container } = render(
|
|
105
105
|
<TableContainer
|
|
@@ -107,7 +107,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
107
107
|
width: 1800,
|
|
108
108
|
lineLength: 720,
|
|
109
109
|
}}
|
|
110
|
-
node={
|
|
110
|
+
node={table}
|
|
111
111
|
isTableResizingEnabled={isTableResizingEnabled}
|
|
112
112
|
isBreakoutEnabled={isBreakoutEnabled}
|
|
113
113
|
className={''}
|
|
@@ -121,12 +121,12 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
121
121
|
return container;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
test('when isTableResizingEnabled is true
|
|
124
|
+
test('should not render resizer when isTableResizingEnabled is true', () => {
|
|
125
125
|
const container = buildContainer(true);
|
|
126
126
|
expect(!!container.querySelector('.resizer-item')).toBeFalsy();
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
test('when isTableResizingEnabled is false
|
|
129
|
+
test('should not render resizer when isTableResizingEnabled is false', () => {
|
|
130
130
|
const container = buildContainer(false);
|
|
131
131
|
expect(!!container.querySelector('.resizer-item')).toBeFalsy();
|
|
132
132
|
});
|
|
@@ -134,13 +134,13 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
134
134
|
|
|
135
135
|
describe('sets width and margin correctly for resizable container', () => {
|
|
136
136
|
const buildContainer = (attrs: TableAttributes) => {
|
|
137
|
-
const {
|
|
137
|
+
const { table, editorView } = createNode(attrs);
|
|
138
138
|
|
|
139
139
|
const { container } = render(
|
|
140
140
|
<ResizableTableContainer
|
|
141
141
|
containerWidth={1800}
|
|
142
142
|
lineLength={720}
|
|
143
|
-
node={
|
|
143
|
+
node={table}
|
|
144
144
|
className={''}
|
|
145
145
|
editorView={editorView}
|
|
146
146
|
getPos={() => 1}
|
|
@@ -162,14 +162,14 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
162
162
|
|
|
163
163
|
describe('analytics', () => {
|
|
164
164
|
const buildContainer = (attrs: TableAttributes) => {
|
|
165
|
-
const {
|
|
165
|
+
const { table, editorView } = createNode(attrs);
|
|
166
166
|
const analyticsMock = jest.fn();
|
|
167
167
|
|
|
168
168
|
const { container } = render(
|
|
169
169
|
<ResizableTableContainer
|
|
170
170
|
containerWidth={1800}
|
|
171
171
|
lineLength={720}
|
|
172
|
-
node={
|
|
172
|
+
node={table}
|
|
173
173
|
className={''}
|
|
174
174
|
editorView={editorView}
|
|
175
175
|
getPos={() => 0}
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
insertColgroupFromNode as recreateResizeColsByNode,
|
|
32
32
|
scaleTable,
|
|
33
33
|
} from '../pm-plugins/table-resizing/utils';
|
|
34
|
+
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
34
35
|
import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
|
|
35
36
|
import {
|
|
36
37
|
TableCssClassName as ClassName,
|
|
@@ -562,8 +563,24 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
562
563
|
|
|
563
564
|
// If column has been inserted/deleted avoid multi dispatch
|
|
564
565
|
if (shouldScaleTable) {
|
|
565
|
-
this.scaleTable({
|
|
566
|
+
this.scaleTable({
|
|
567
|
+
parentWidth,
|
|
568
|
+
layoutChanged,
|
|
569
|
+
isTableResizingEnabled: options?.isTableResizingEnabled,
|
|
570
|
+
});
|
|
566
571
|
}
|
|
572
|
+
|
|
573
|
+
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
574
|
+
if (options?.isTableResizingEnabled && hasNumberedColumnChanged) {
|
|
575
|
+
if (!hasTableBeenResized(prevNode)) {
|
|
576
|
+
this.scaleTable({
|
|
577
|
+
parentWidth,
|
|
578
|
+
layoutChanged,
|
|
579
|
+
isTableResizingEnabled: options?.isTableResizingEnabled,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
567
584
|
this.updateParentWidth(parentWidth);
|
|
568
585
|
}
|
|
569
586
|
|
|
@@ -575,6 +592,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
575
592
|
private scaleTable = (scaleOptions: {
|
|
576
593
|
layoutChanged: boolean;
|
|
577
594
|
parentWidth?: number;
|
|
595
|
+
isTableResizingEnabled?: boolean;
|
|
578
596
|
}) => {
|
|
579
597
|
const { view, getNode, getPos, containerWidth, options } = this.props;
|
|
580
598
|
const node = getNode();
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from '@atlaskit/editor-common/resizer';
|
|
26
26
|
import type { GuidelineConfig } from '@atlaskit/editor-plugin-guideline';
|
|
27
27
|
import { TableMap } from '@atlaskit/editor-tables';
|
|
28
|
+
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
28
29
|
|
|
29
30
|
import {
|
|
30
31
|
COLUMN_MIN_WIDTH,
|
|
@@ -38,7 +39,6 @@ import { TABLE_HIGHLIGHT_GAP, TABLE_SNAP_GAP } from '../ui/consts';
|
|
|
38
39
|
import { getTableWidth } from '../utils';
|
|
39
40
|
import { defaultGuidelines, defaultGuidelineWidths } from '../utils/guidelines';
|
|
40
41
|
import { findClosestSnap } from '../utils/snapping';
|
|
41
|
-
|
|
42
42
|
interface TableResizerProps {
|
|
43
43
|
width: number;
|
|
44
44
|
maxWidth: number;
|
|
@@ -79,24 +79,7 @@ const generateResizedPayload = (props: {
|
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
children,
|
|
84
|
-
width,
|
|
85
|
-
maxWidth,
|
|
86
|
-
updateWidth,
|
|
87
|
-
editorView,
|
|
88
|
-
getPos,
|
|
89
|
-
node,
|
|
90
|
-
tableRef,
|
|
91
|
-
displayGuideline,
|
|
92
|
-
attachAnalyticsEvent,
|
|
93
|
-
}: PropsWithChildren<TableResizerProps>) => {
|
|
94
|
-
const currentColumnCount = getColgroupChildrenLength(node);
|
|
95
|
-
const minColumnWidth =
|
|
96
|
-
currentColumnCount <= 3
|
|
97
|
-
? currentColumnCount * COLUMN_MIN_WIDTH
|
|
98
|
-
: 3 * COLUMN_MIN_WIDTH;
|
|
99
|
-
|
|
82
|
+
const getResizerHandleHeight = (tableRef: HTMLTableElement) => {
|
|
100
83
|
const tableHeight = tableRef?.clientHeight;
|
|
101
84
|
let handleHeightSize: HandleHeightSizeType | undefined = 'small';
|
|
102
85
|
/*
|
|
@@ -113,9 +96,38 @@ export const TableResizer = ({
|
|
|
113
96
|
} else if (tableHeight && tableHeight >= 96) {
|
|
114
97
|
handleHeightSize = 'large';
|
|
115
98
|
}
|
|
99
|
+
|
|
100
|
+
return handleHeightSize;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const getResizerMinWidth = (node: PMNode) => {
|
|
104
|
+
const currentColumnCount = getColgroupChildrenLength(node);
|
|
105
|
+
const minColumnWidth =
|
|
106
|
+
currentColumnCount <= 3
|
|
107
|
+
? currentColumnCount * COLUMN_MIN_WIDTH
|
|
108
|
+
: 3 * COLUMN_MIN_WIDTH;
|
|
109
|
+
|
|
110
|
+
return minColumnWidth;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const TableResizer = ({
|
|
114
|
+
children,
|
|
115
|
+
width,
|
|
116
|
+
maxWidth,
|
|
117
|
+
updateWidth,
|
|
118
|
+
editorView,
|
|
119
|
+
getPos,
|
|
120
|
+
node,
|
|
121
|
+
tableRef,
|
|
122
|
+
displayGuideline,
|
|
123
|
+
attachAnalyticsEvent,
|
|
124
|
+
}: PropsWithChildren<TableResizerProps>) => {
|
|
116
125
|
const currentGap = useRef(0);
|
|
117
126
|
const [snappingEnabled, setSnappingEnabled] = useState(false);
|
|
118
127
|
|
|
128
|
+
const resizerMinWidth = getResizerMinWidth(node);
|
|
129
|
+
const handleHeightSize = getResizerHandleHeight(tableRef);
|
|
130
|
+
|
|
119
131
|
const updateActiveGuidelines = useCallback(
|
|
120
132
|
({ gap, keys }: { gap: number; keys: string[] }) => {
|
|
121
133
|
if (gap !== currentGap.current) {
|
|
@@ -152,8 +164,7 @@ export const TableResizer = ({
|
|
|
152
164
|
dispatch(tr.setMeta(tableWidthPluginKey, { resizing: true }));
|
|
153
165
|
|
|
154
166
|
setSnappingEnabled(displayGuideline(defaultGuidelines));
|
|
155
|
-
|
|
156
|
-
}, [width, displayGuideline, editorView]);
|
|
167
|
+
}, [displayGuideline, editorView]);
|
|
157
168
|
|
|
158
169
|
const handleResizeStop = useCallback<HandleResize>(
|
|
159
170
|
(originalState, delta) => {
|
|
@@ -258,11 +269,12 @@ export const TableResizer = ({
|
|
|
258
269
|
handleResize={scheduleResize}
|
|
259
270
|
handleResizeStop={handleResizeStop}
|
|
260
271
|
resizeRatio={2}
|
|
261
|
-
minWidth={
|
|
272
|
+
minWidth={resizerMinWidth}
|
|
262
273
|
maxWidth={maxWidth}
|
|
263
274
|
snapGap={TABLE_SNAP_GAP}
|
|
264
275
|
snap={guidelineSnaps}
|
|
265
276
|
handlePositioning="adjacent"
|
|
277
|
+
isHandleVisible={findTable(editorView.state?.selection)?.pos === getPos()}
|
|
266
278
|
>
|
|
267
279
|
{children}
|
|
268
280
|
</ResizerNext>
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
getPosHandlerNode,
|
|
21
21
|
} from '@atlaskit/editor-common/types';
|
|
22
22
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
23
|
+
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
23
24
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
24
25
|
|
|
25
26
|
import { pluginConfig as getPluginConfig } from '../create-plugin-config';
|
|
@@ -49,7 +50,11 @@ const tableAttributes = (
|
|
|
49
50
|
options?.isTableResizingEnabled && !isTableNested(state, pos);
|
|
50
51
|
|
|
51
52
|
let style = shouldHaveInlineWidth
|
|
52
|
-
? `width: ${
|
|
53
|
+
? `width: ${
|
|
54
|
+
node.attrs.isNumberColumnEnabled
|
|
55
|
+
? getTableContainerWidth(node) - akEditorTableNumberColumnWidth
|
|
56
|
+
: getTableContainerWidth(node)
|
|
57
|
+
}px`
|
|
53
58
|
: undefined;
|
|
54
59
|
|
|
55
60
|
return {
|
|
@@ -2,6 +2,7 @@ import { Node as PMNode } from 'prosemirror-model';
|
|
|
2
2
|
import { Transaction } from 'prosemirror-state';
|
|
3
3
|
import type { DomAtPos } from 'prosemirror-utils';
|
|
4
4
|
|
|
5
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
5
6
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
6
7
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
7
8
|
|
|
@@ -29,6 +30,7 @@ export interface ScaleOptions {
|
|
|
29
30
|
layoutChanged?: boolean;
|
|
30
31
|
isBreakoutEnabled?: boolean;
|
|
31
32
|
isFullWidthModeEnabled?: boolean;
|
|
33
|
+
isTableResizingEnabled?: boolean;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
// Base function to trigger the actual scale on a table node.
|
|
@@ -51,24 +53,27 @@ export const scale = (
|
|
|
51
53
|
start,
|
|
52
54
|
isBreakoutEnabled,
|
|
53
55
|
layoutChanged,
|
|
56
|
+
isTableResizingEnabled,
|
|
54
57
|
} = options;
|
|
55
58
|
|
|
56
|
-
const maxSize =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
const maxSize = isTableResizingEnabled
|
|
60
|
+
? getTableContainerWidth(node)
|
|
61
|
+
: getLayoutSize(node.attrs.layout, containerWidth, {
|
|
62
|
+
isBreakoutEnabled,
|
|
63
|
+
});
|
|
64
|
+
|
|
59
65
|
const prevTableWidth = getTableWidth(prevNode);
|
|
60
|
-
const previousMaxSize =
|
|
61
|
-
|
|
62
|
-
previousContainerWidth,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
);
|
|
66
|
+
const previousMaxSize = isTableResizingEnabled
|
|
67
|
+
? getTableContainerWidth(node)
|
|
68
|
+
: getLayoutSize(prevNode.attrs.layout, previousContainerWidth, {
|
|
69
|
+
isBreakoutEnabled,
|
|
70
|
+
});
|
|
67
71
|
|
|
68
72
|
let newWidth = maxSize;
|
|
69
73
|
|
|
70
74
|
// adjust table width if layout is updated
|
|
71
75
|
const hasOverflow = prevTableWidth > previousMaxSize;
|
|
76
|
+
|
|
72
77
|
if (layoutChanged && hasOverflow) {
|
|
73
78
|
// No keep overflow if the old content can be in the new size
|
|
74
79
|
const canFitInNewSize = prevTableWidth < maxSize;
|
|
@@ -157,7 +162,11 @@ export const previewScaleTable = (
|
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
if (parentWidth) {
|
|
160
|
-
|
|
165
|
+
const isNumberColumnEnabled = node.attrs.isNumberColumnEnabled;
|
|
166
|
+
const width = isNumberColumnEnabled
|
|
167
|
+
? parentWidth - akEditorTableNumberColumnWidth
|
|
168
|
+
: parentWidth;
|
|
169
|
+
tableRef.style.width = `${width}px`;
|
|
161
170
|
}
|
|
162
171
|
|
|
163
172
|
if (!hasTableBeenResized(node)) {
|
|
@@ -186,12 +195,12 @@ export const scaleTable =
|
|
|
186
195
|
}
|
|
187
196
|
|
|
188
197
|
const { node, start, parentWidth, layoutChanged } = options;
|
|
189
|
-
|
|
190
198
|
// If a table has not been resized yet, columns should be auto.
|
|
191
199
|
if (hasTableBeenResized(node) === false) {
|
|
192
200
|
// If its not a re-sized table, we still want to re-create cols
|
|
193
201
|
// To force reflow of columns upon delete.
|
|
194
202
|
insertColgroupFromNode(tableRef, node);
|
|
203
|
+
tr.setMeta('scrollIntoView', false);
|
|
195
204
|
return tr;
|
|
196
205
|
}
|
|
197
206
|
|