@atlaskit/editor-plugin-table 2.5.5 → 2.6.1
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 +16 -0
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +6 -2
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +49 -18
- package/dist/cjs/plugins/table/nodeviews/table.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -5
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +6 -2
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +48 -19
- package/dist/es2019/plugins/table/nodeviews/table.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -5
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +6 -2
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +50 -19
- package/dist/esm/plugins/table/nodeviews/table.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -5
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +4 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +4 -1
- 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 +74 -11
- package/src/plugins/table/nodeviews/TableComponent.tsx +19 -1
- package/src/plugins/table/nodeviews/TableContainer.tsx +11 -4
- package/src/plugins/table/nodeviews/TableResizer.tsx +94 -32
- package/src/plugins/table/nodeviews/table.tsx +6 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +20 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 2.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`84516fbd72d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/84516fbd72d) - [ux] ED-19068: fix numbered columns scroll bar issue
|
|
8
|
+
|
|
9
|
+
## 2.6.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`0ae6f70038a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0ae6f70038a) - [ED-17635] Add analytics event for table width resizing
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 2.5.5
|
|
4
20
|
|
|
5
21
|
### Patch 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;
|
|
@@ -71,8 +71,11 @@ var ResizableTableContainer = function ResizableTableContainer(_ref2) {
|
|
|
71
71
|
guidelines: guidelines
|
|
72
72
|
})) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : false;
|
|
73
73
|
}, [pluginInjectionApi, editorView]);
|
|
74
|
+
var attachAnalyticsEvent = (0, _react.useCallback)(function (payload) {
|
|
75
|
+
var _pluginInjectionApi$d5;
|
|
76
|
+
return pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d5 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d5 === void 0 ? void 0 : _pluginInjectionApi$d5.analytics.actions.attachAnalyticsEvent(payload);
|
|
77
|
+
}, [pluginInjectionApi]);
|
|
74
78
|
var tableWidth = (0, _nodeWidth.getTableContainerWidth)(node);
|
|
75
|
-
|
|
76
79
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
77
80
|
var responsiveContainerWidth = containerWidth - 76;
|
|
78
81
|
var width = Math.min(tableWidth, responsiveContainerWidth);
|
|
@@ -93,7 +96,8 @@ var ResizableTableContainer = function ResizableTableContainer(_ref2) {
|
|
|
93
96
|
getPos: getPos,
|
|
94
97
|
node: node,
|
|
95
98
|
tableRef: tableRef,
|
|
96
|
-
displayGuideline: displayGuideline
|
|
99
|
+
displayGuideline: displayGuideline,
|
|
100
|
+
attachAnalyticsEvent: attachAnalyticsEvent
|
|
97
101
|
}, /*#__PURE__*/_react.default.createElement(InnerContainer, {
|
|
98
102
|
className: className,
|
|
99
103
|
node: node
|
|
@@ -10,11 +10,14 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
12
|
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
13
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
14
|
var _guideline = require("@atlaskit/editor-common/guideline");
|
|
14
15
|
var _resizer = require("@atlaskit/editor-common/resizer");
|
|
16
|
+
var _editorTables = require("@atlaskit/editor-tables");
|
|
15
17
|
var _utils = require("../pm-plugins/table-resizing/utils");
|
|
16
18
|
var _tableWidth = require("../pm-plugins/table-width");
|
|
17
19
|
var _consts = require("../ui/consts");
|
|
20
|
+
var _utils2 = require("../utils");
|
|
18
21
|
var _guidelines = require("../utils/guidelines");
|
|
19
22
|
var _snapping = require("../utils/snapping");
|
|
20
23
|
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); }
|
|
@@ -25,6 +28,23 @@ var handles = {
|
|
|
25
28
|
right: true
|
|
26
29
|
};
|
|
27
30
|
var tableHandleMarginTop = 11;
|
|
31
|
+
var generateResizedPayload = function generateResizedPayload(props) {
|
|
32
|
+
var _props$originalNode$a;
|
|
33
|
+
var tableMap = _editorTables.TableMap.get(props.resizedNode);
|
|
34
|
+
return {
|
|
35
|
+
action: _analytics.TABLE_ACTION.RESIZED,
|
|
36
|
+
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
|
|
37
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
38
|
+
attributes: {
|
|
39
|
+
newWidth: props.resizedNode.attrs.width,
|
|
40
|
+
prevWidth: (_props$originalNode$a = props.originalNode.attrs.width) !== null && _props$originalNode$a !== void 0 ? _props$originalNode$a : null,
|
|
41
|
+
nodeSize: props.resizedNode.nodeSize,
|
|
42
|
+
totalTableWidth: (0, _utils.hasTableBeenResized)(props.resizedNode) ? (0, _utils2.getTableWidth)(props.resizedNode) : null,
|
|
43
|
+
totalRowCount: tableMap.height,
|
|
44
|
+
totalColumnCount: tableMap.width
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
28
48
|
var TableResizer = function TableResizer(_ref) {
|
|
29
49
|
var children = _ref.children,
|
|
30
50
|
width = _ref.width,
|
|
@@ -34,7 +54,8 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
34
54
|
getPos = _ref.getPos,
|
|
35
55
|
node = _ref.node,
|
|
36
56
|
tableRef = _ref.tableRef,
|
|
37
|
-
displayGuideline = _ref.displayGuideline
|
|
57
|
+
displayGuideline = _ref.displayGuideline,
|
|
58
|
+
attachAnalyticsEvent = _ref.attachAnalyticsEvent;
|
|
38
59
|
var currentColumnCount = (0, _utils.getColgroupChildrenLength)(node);
|
|
39
60
|
var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * _utils.COLUMN_MIN_WIDTH : 3 * _utils.COLUMN_MIN_WIDTH;
|
|
40
61
|
var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
|
|
@@ -88,6 +109,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
88
109
|
resizing: false
|
|
89
110
|
});
|
|
90
111
|
if (typeof pos === 'number') {
|
|
112
|
+
var _attachAnalyticsEvent;
|
|
91
113
|
tr = tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
92
114
|
width: newWidth
|
|
93
115
|
}));
|
|
@@ -98,6 +120,11 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
98
120
|
start: pos + 1,
|
|
99
121
|
parentWidth: newWidth
|
|
100
122
|
}, editorView.domAtPos.bind(editorView))(tr);
|
|
123
|
+
var scaledNode = tr.doc.nodeAt(pos);
|
|
124
|
+
(_attachAnalyticsEvent = attachAnalyticsEvent(generateResizedPayload({
|
|
125
|
+
originalNode: node,
|
|
126
|
+
resizedNode: scaledNode
|
|
127
|
+
}))) === null || _attachAnalyticsEvent === void 0 ? void 0 : _attachAnalyticsEvent(tr);
|
|
101
128
|
}
|
|
102
129
|
dispatch(tr);
|
|
103
130
|
|
|
@@ -105,7 +132,26 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
105
132
|
displayGuideline([]);
|
|
106
133
|
updateWidth(newWidth);
|
|
107
134
|
return newWidth;
|
|
108
|
-
}, [updateWidth, editorView, getPos, node, tableRef, displayGuideline]);
|
|
135
|
+
}, [updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent]);
|
|
136
|
+
var handleResize = (0, _react.useCallback)(function (originalState, delta) {
|
|
137
|
+
var newWidth = originalState.width + delta.width;
|
|
138
|
+
var pos = getPos();
|
|
139
|
+
if (typeof pos !== 'number') {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
(0, _utils.previewScaleTable)(tableRef, {
|
|
143
|
+
node: node,
|
|
144
|
+
prevNode: node,
|
|
145
|
+
start: pos + 1,
|
|
146
|
+
parentWidth: newWidth
|
|
147
|
+
}, editorView.domAtPos.bind(editorView));
|
|
148
|
+
updateActiveGuidelines((0, _snapping.findClosestSnap)(newWidth, _guidelines.defaultGuidelineWidths, _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP));
|
|
149
|
+
updateWidth(newWidth);
|
|
150
|
+
return newWidth;
|
|
151
|
+
}, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines]);
|
|
152
|
+
var scheduleResize = (0, _react.useMemo)(function () {
|
|
153
|
+
return (0, _rafSchd.default)(handleResize);
|
|
154
|
+
}, [handleResize]);
|
|
109
155
|
return /*#__PURE__*/_react.default.createElement(_resizer.ResizerNext, {
|
|
110
156
|
enable: handles,
|
|
111
157
|
width: width,
|
|
@@ -113,22 +159,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
113
159
|
handleHeightSize: handleHeightSize,
|
|
114
160
|
handleMarginTop: tableHandleMarginTop,
|
|
115
161
|
handleResizeStart: handleResizeStart,
|
|
116
|
-
handleResize:
|
|
117
|
-
var newWidth = originalState.width + delta.width;
|
|
118
|
-
var pos = getPos();
|
|
119
|
-
if (typeof pos !== 'number') {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
(0, _utils.previewScaleTable)(tableRef, {
|
|
123
|
-
node: node,
|
|
124
|
-
prevNode: node,
|
|
125
|
-
start: pos + 1,
|
|
126
|
-
parentWidth: newWidth
|
|
127
|
-
}, editorView.domAtPos.bind(editorView));
|
|
128
|
-
updateActiveGuidelines((0, _snapping.findClosestSnap)(newWidth, _guidelines.defaultGuidelineWidths, _guidelines.defaultGuidelines, _consts.TABLE_HIGHLIGHT_GAP));
|
|
129
|
-
updateWidth(newWidth);
|
|
130
|
-
return newWidth;
|
|
131
|
-
}),
|
|
162
|
+
handleResize: scheduleResize,
|
|
132
163
|
handleResizeStop: handleResizeStop,
|
|
133
164
|
resizeRatio: 2,
|
|
134
165
|
minWidth: minColumnWidth,
|
|
@@ -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,7 +142,6 @@ 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
|
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;
|
|
@@ -62,8 +62,11 @@ export const ResizableTableContainer = ({
|
|
|
62
62
|
guidelines
|
|
63
63
|
})) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : false;
|
|
64
64
|
}, [pluginInjectionApi, editorView]);
|
|
65
|
+
const attachAnalyticsEvent = useCallback(payload => {
|
|
66
|
+
var _pluginInjectionApi$d5;
|
|
67
|
+
return pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d5 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d5 === void 0 ? void 0 : _pluginInjectionApi$d5.analytics.actions.attachAnalyticsEvent(payload);
|
|
68
|
+
}, [pluginInjectionApi]);
|
|
65
69
|
const tableWidth = getTableContainerWidth(node);
|
|
66
|
-
|
|
67
70
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
68
71
|
const responsiveContainerWidth = containerWidth - 76;
|
|
69
72
|
const width = Math.min(tableWidth, responsiveContainerWidth);
|
|
@@ -84,7 +87,8 @@ export const ResizableTableContainer = ({
|
|
|
84
87
|
getPos: getPos,
|
|
85
88
|
node: node,
|
|
86
89
|
tableRef: tableRef,
|
|
87
|
-
displayGuideline: displayGuideline
|
|
90
|
+
displayGuideline: displayGuideline,
|
|
91
|
+
attachAnalyticsEvent: attachAnalyticsEvent
|
|
88
92
|
}, /*#__PURE__*/React.createElement(InnerContainer, {
|
|
89
93
|
className: className,
|
|
90
94
|
node: node
|
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import rafSchd from 'raf-schd';
|
|
3
|
+
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
3
4
|
import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
|
|
4
5
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
5
|
-
import {
|
|
6
|
+
import { TableMap } from '@atlaskit/editor-tables';
|
|
7
|
+
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, hasTableBeenResized, previewScaleTable, scaleTable } from '../pm-plugins/table-resizing/utils';
|
|
6
8
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
7
9
|
import { TABLE_HIGHLIGHT_GAP, TABLE_SNAP_GAP } from '../ui/consts';
|
|
10
|
+
import { getTableWidth } from '../utils';
|
|
8
11
|
import { defaultGuidelines, defaultGuidelineWidths } from '../utils/guidelines';
|
|
9
12
|
import { findClosestSnap } from '../utils/snapping';
|
|
10
13
|
const handles = {
|
|
11
14
|
right: true
|
|
12
15
|
};
|
|
13
16
|
const tableHandleMarginTop = 11;
|
|
17
|
+
const generateResizedPayload = props => {
|
|
18
|
+
var _props$originalNode$a;
|
|
19
|
+
const tableMap = TableMap.get(props.resizedNode);
|
|
20
|
+
return {
|
|
21
|
+
action: TABLE_ACTION.RESIZED,
|
|
22
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
23
|
+
eventType: EVENT_TYPE.TRACK,
|
|
24
|
+
attributes: {
|
|
25
|
+
newWidth: props.resizedNode.attrs.width,
|
|
26
|
+
prevWidth: (_props$originalNode$a = props.originalNode.attrs.width) !== null && _props$originalNode$a !== void 0 ? _props$originalNode$a : null,
|
|
27
|
+
nodeSize: props.resizedNode.nodeSize,
|
|
28
|
+
totalTableWidth: hasTableBeenResized(props.resizedNode) ? getTableWidth(props.resizedNode) : null,
|
|
29
|
+
totalRowCount: tableMap.height,
|
|
30
|
+
totalColumnCount: tableMap.width
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
14
34
|
export const TableResizer = ({
|
|
15
35
|
children,
|
|
16
36
|
width,
|
|
@@ -20,7 +40,8 @@ export const TableResizer = ({
|
|
|
20
40
|
getPos,
|
|
21
41
|
node,
|
|
22
42
|
tableRef,
|
|
23
|
-
displayGuideline
|
|
43
|
+
displayGuideline,
|
|
44
|
+
attachAnalyticsEvent
|
|
24
45
|
}) => {
|
|
25
46
|
const currentColumnCount = getColgroupChildrenLength(node);
|
|
26
47
|
const minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
|
|
@@ -77,6 +98,7 @@ export const TableResizer = ({
|
|
|
77
98
|
resizing: false
|
|
78
99
|
});
|
|
79
100
|
if (typeof pos === 'number') {
|
|
101
|
+
var _attachAnalyticsEvent;
|
|
80
102
|
tr = tr.setNodeMarkup(pos, undefined, {
|
|
81
103
|
...node.attrs,
|
|
82
104
|
width: newWidth
|
|
@@ -88,6 +110,11 @@ export const TableResizer = ({
|
|
|
88
110
|
start: pos + 1,
|
|
89
111
|
parentWidth: newWidth
|
|
90
112
|
}, editorView.domAtPos.bind(editorView))(tr);
|
|
113
|
+
const scaledNode = tr.doc.nodeAt(pos);
|
|
114
|
+
(_attachAnalyticsEvent = attachAnalyticsEvent(generateResizedPayload({
|
|
115
|
+
originalNode: node,
|
|
116
|
+
resizedNode: scaledNode
|
|
117
|
+
}))) === null || _attachAnalyticsEvent === void 0 ? void 0 : _attachAnalyticsEvent(tr);
|
|
91
118
|
}
|
|
92
119
|
dispatch(tr);
|
|
93
120
|
|
|
@@ -95,7 +122,24 @@ export const TableResizer = ({
|
|
|
95
122
|
displayGuideline([]);
|
|
96
123
|
updateWidth(newWidth);
|
|
97
124
|
return newWidth;
|
|
98
|
-
}, [updateWidth, editorView, getPos, node, tableRef, displayGuideline]);
|
|
125
|
+
}, [updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent]);
|
|
126
|
+
const handleResize = useCallback((originalState, delta) => {
|
|
127
|
+
const newWidth = originalState.width + delta.width;
|
|
128
|
+
const pos = getPos();
|
|
129
|
+
if (typeof pos !== 'number') {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
previewScaleTable(tableRef, {
|
|
133
|
+
node,
|
|
134
|
+
prevNode: node,
|
|
135
|
+
start: pos + 1,
|
|
136
|
+
parentWidth: newWidth
|
|
137
|
+
}, editorView.domAtPos.bind(editorView));
|
|
138
|
+
updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
|
|
139
|
+
updateWidth(newWidth);
|
|
140
|
+
return newWidth;
|
|
141
|
+
}, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines]);
|
|
142
|
+
const scheduleResize = useMemo(() => rafSchd(handleResize), [handleResize]);
|
|
99
143
|
return /*#__PURE__*/React.createElement(ResizerNext, {
|
|
100
144
|
enable: handles,
|
|
101
145
|
width: width,
|
|
@@ -103,22 +147,7 @@ export const TableResizer = ({
|
|
|
103
147
|
handleHeightSize: handleHeightSize,
|
|
104
148
|
handleMarginTop: tableHandleMarginTop,
|
|
105
149
|
handleResizeStart: handleResizeStart,
|
|
106
|
-
handleResize:
|
|
107
|
-
const newWidth = originalState.width + delta.width;
|
|
108
|
-
const pos = getPos();
|
|
109
|
-
if (typeof pos !== 'number') {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
previewScaleTable(tableRef, {
|
|
113
|
-
node,
|
|
114
|
-
prevNode: node,
|
|
115
|
-
start: pos + 1,
|
|
116
|
-
parentWidth: newWidth
|
|
117
|
-
}, editorView.domAtPos.bind(editorView));
|
|
118
|
-
updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
|
|
119
|
-
updateWidth(newWidth);
|
|
120
|
-
return newWidth;
|
|
121
|
-
}),
|
|
150
|
+
handleResize: scheduleResize,
|
|
122
151
|
handleResizeStop: handleResizeStop,
|
|
123
152
|
resizeRatio: 2,
|
|
124
153
|
minWidth: minColumnWidth,
|
|
@@ -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,7 +136,6 @@ 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
|
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;
|
|
@@ -60,8 +60,11 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
|
|
|
60
60
|
guidelines: guidelines
|
|
61
61
|
})) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : false;
|
|
62
62
|
}, [pluginInjectionApi, editorView]);
|
|
63
|
+
var attachAnalyticsEvent = useCallback(function (payload) {
|
|
64
|
+
var _pluginInjectionApi$d5;
|
|
65
|
+
return pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d5 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d5 === void 0 ? void 0 : _pluginInjectionApi$d5.analytics.actions.attachAnalyticsEvent(payload);
|
|
66
|
+
}, [pluginInjectionApi]);
|
|
63
67
|
var tableWidth = getTableContainerWidth(node);
|
|
64
|
-
|
|
65
68
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
66
69
|
var responsiveContainerWidth = containerWidth - 76;
|
|
67
70
|
var width = Math.min(tableWidth, responsiveContainerWidth);
|
|
@@ -82,7 +85,8 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
|
|
|
82
85
|
getPos: getPos,
|
|
83
86
|
node: node,
|
|
84
87
|
tableRef: tableRef,
|
|
85
|
-
displayGuideline: displayGuideline
|
|
88
|
+
displayGuideline: displayGuideline,
|
|
89
|
+
attachAnalyticsEvent: attachAnalyticsEvent
|
|
86
90
|
}, /*#__PURE__*/React.createElement(InnerContainer, {
|
|
87
91
|
className: className,
|
|
88
92
|
node: node
|