@atlaskit/editor-plugin-table 1.7.3 → 2.0.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 +15 -0
- package/dist/cjs/plugins/table/index.js +11 -16
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +7 -3
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +23 -19
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +2 -1
- package/dist/cjs/plugins/table/nodeviews/table.js +5 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/index.js +11 -16
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +7 -3
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +22 -18
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +3 -2
- package/dist/es2019/plugins/table/nodeviews/table.js +5 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/index.js +11 -16
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +7 -3
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +23 -19
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +3 -2
- package/dist/esm/plugins/table/nodeviews/table.js +5 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/index.d.ts +0 -2
- package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +5 -3
- package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/index.d.ts +0 -2
- package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +5 -3
- package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +2 -1
- package/package.json +5 -7
- package/report.api.md +0 -3
- package/src/__tests__/unit/analytics.ts +20 -10
- package/src/__tests__/unit/keymap.ts +14 -21
- package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +12 -7
- package/src/plugins/table/index.tsx +12 -25
- package/src/plugins/table/nodeviews/TableComponent.tsx +10 -4
- package/src/plugins/table/nodeviews/TableContainer.tsx +28 -19
- package/src/plugins/table/nodeviews/TableResizer.tsx +3 -2
- package/src/plugins/table/nodeviews/table.tsx +6 -0
- package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +10 -1
- package/tmp/api-report-tmp.d.ts +0 -107
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`802453ec412`](https://bitbucket.org/atlassian/atlassian-frontend/commits/802453ec412) - [ux] update how table respond to external width changes under `platform.editor.custom-table-width` feature flag
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 2.0.0
|
|
11
|
+
|
|
12
|
+
### Major Changes
|
|
13
|
+
|
|
14
|
+
- [`bdb840c6eaa`](https://bitbucket.org/atlassian/atlassian-frontend/commits/bdb840c6eaa) - Remove EditorAnalyticsAPI parameter from tables plugin as it now gets this from `editor-plugin-analytics`. This parameter is unused and the action is just to remove it.
|
|
15
|
+
|
|
16
|
+
Fix issue where internal analytics plugin was not being called correctly.
|
|
17
|
+
|
|
3
18
|
## 1.7.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -40,6 +40,7 @@ var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
|
|
|
40
40
|
return {};
|
|
41
41
|
};
|
|
42
42
|
var tablesPlugin = function tablesPlugin(options, api) {
|
|
43
|
+
var _api$dependencies$ana;
|
|
43
44
|
var editorViewRef = {
|
|
44
45
|
current: null
|
|
45
46
|
};
|
|
@@ -50,6 +51,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
50
51
|
};
|
|
51
52
|
return (_api$dependencies$wid = api === null || api === void 0 ? void 0 : api.dependencies.width.sharedState.currentState()) !== null && _api$dependencies$wid !== void 0 ? _api$dependencies$wid : defaultState;
|
|
52
53
|
};
|
|
54
|
+
var editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions;
|
|
53
55
|
return {
|
|
54
56
|
name: 'table',
|
|
55
57
|
actions: {
|
|
@@ -91,19 +93,15 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
91
93
|
var plugins = [{
|
|
92
94
|
name: 'table',
|
|
93
95
|
plugin: function plugin(_ref) {
|
|
94
|
-
var _api$dependencies$ana;
|
|
95
96
|
var dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
96
97
|
dispatch = _ref.dispatch,
|
|
97
98
|
portalProviderAPI = _ref.portalProviderAPI,
|
|
98
99
|
eventDispatcher = _ref.eventDispatcher;
|
|
99
|
-
var _ref2 = options || {
|
|
100
|
-
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions
|
|
101
|
-
},
|
|
100
|
+
var _ref2 = options || {},
|
|
102
101
|
fullWidthEnabled = _ref2.fullWidthEnabled,
|
|
103
102
|
wasFullWidthEnabled = _ref2.wasFullWidthEnabled,
|
|
104
103
|
breakoutEnabled = _ref2.breakoutEnabled,
|
|
105
104
|
tableOptions = _ref2.tableOptions,
|
|
106
|
-
editorAnalyticsAPI = _ref2.editorAnalyticsAPI,
|
|
107
105
|
getEditorFeatureFlags = _ref2.getEditorFeatureFlags;
|
|
108
106
|
return (0, _main.createPlugin)(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, (0, _createPluginConfig.pluginConfig)(tableOptions), defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, breakoutEnabled, fullWidthEnabled, wasFullWidthEnabled, editorAnalyticsAPI);
|
|
109
107
|
}
|
|
@@ -114,7 +112,6 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
114
112
|
var _ref4 = options || {},
|
|
115
113
|
fullWidthEnabled = _ref4.fullWidthEnabled,
|
|
116
114
|
tableOptions = _ref4.tableOptions,
|
|
117
|
-
editorAnalyticsAPI = _ref4.editorAnalyticsAPI,
|
|
118
115
|
getEditorFeatureFlags = _ref4.getEditorFeatureFlags;
|
|
119
116
|
var _pluginConfig = (0, _createPluginConfig.pluginConfig)(tableOptions),
|
|
120
117
|
allowColumnResizing = _pluginConfig.allowColumnResizing;
|
|
@@ -133,7 +130,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
133
130
|
{
|
|
134
131
|
name: 'tableKeymap',
|
|
135
132
|
plugin: function plugin() {
|
|
136
|
-
return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth,
|
|
133
|
+
return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth, editorAnalyticsAPI);
|
|
137
134
|
}
|
|
138
135
|
}, {
|
|
139
136
|
name: 'tableSelectionKeymap',
|
|
@@ -145,11 +142,10 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
145
142
|
plugin: function plugin() {
|
|
146
143
|
return (0, _pmPlugins.tableEditing)({
|
|
147
144
|
reportFixedTable: function reportFixedTable(_ref5) {
|
|
148
|
-
var _options$editorAnalyt;
|
|
149
145
|
var state = _ref5.state,
|
|
150
146
|
tr = _ref5.tr,
|
|
151
147
|
reason = _ref5.reason;
|
|
152
|
-
|
|
148
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
153
149
|
action: _analytics.TABLE_ACTION.FIXED,
|
|
154
150
|
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
|
|
155
151
|
actionSubjectId: null,
|
|
@@ -256,7 +252,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
256
252
|
layout: layout,
|
|
257
253
|
isResizing: !!resizingPluginState && !!resizingPluginState.dragging,
|
|
258
254
|
stickyHeader: stickyHeader,
|
|
259
|
-
editorAnalyticsAPI:
|
|
255
|
+
editorAnalyticsAPI: editorAnalyticsAPI
|
|
260
256
|
}) : null;
|
|
261
257
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, targetCellPosition && tableRef && !isDragging && options && options.allowContextualMenu && /*#__PURE__*/_react.default.createElement(_FloatingContextualButton.default, {
|
|
262
258
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
@@ -283,7 +279,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
283
279
|
scrollableElement: popupsScrollableElement,
|
|
284
280
|
hasStickyHeaders: stickyHeader && stickyHeader.sticky,
|
|
285
281
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
286
|
-
editorAnalyticsAPI:
|
|
282
|
+
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
287
283
|
getEditorContainerWidth: defaultGetEditorContainerWidth
|
|
288
284
|
}), /*#__PURE__*/_react.default.createElement(_FloatingContextualMenu.default, {
|
|
289
285
|
editorView: editorView,
|
|
@@ -292,7 +288,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
292
288
|
targetCellPosition: targetCellPosition,
|
|
293
289
|
isOpen: Boolean(isContextualMenuOpen),
|
|
294
290
|
pluginConfig: pluginConfig,
|
|
295
|
-
editorAnalyticsAPI:
|
|
291
|
+
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
296
292
|
getEditorContainerWidth: defaultGetEditorContainerWidth,
|
|
297
293
|
getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
|
|
298
294
|
}), allowControls && /*#__PURE__*/_react.default.createElement(_FloatingDeleteButton.default, {
|
|
@@ -304,7 +300,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
304
300
|
scrollableElement: popupsScrollableElement,
|
|
305
301
|
stickyHeaders: stickyHeader,
|
|
306
302
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
307
|
-
editorAnalyticsAPI:
|
|
303
|
+
editorAnalyticsAPI: editorAnalyticsAPI
|
|
308
304
|
}), LayoutContent);
|
|
309
305
|
}
|
|
310
306
|
}));
|
|
@@ -323,11 +319,10 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
323
319
|
return /*#__PURE__*/_react.default.createElement(_icons.IconTable, null);
|
|
324
320
|
},
|
|
325
321
|
action: function action(insert, state) {
|
|
326
|
-
var _options$editorAnalyt2;
|
|
327
322
|
var tr = insert((0, _utils2.createTable)({
|
|
328
323
|
schema: state.schema
|
|
329
324
|
}));
|
|
330
|
-
|
|
325
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
331
326
|
action: _analytics.ACTION.INSERTED,
|
|
332
327
|
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
333
328
|
actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE,
|
|
@@ -340,7 +335,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
340
335
|
}
|
|
341
336
|
}];
|
|
342
337
|
},
|
|
343
|
-
floatingToolbar: (0, _toolbar.getToolbarConfig)(defaultGetEditorContainerWidth,
|
|
338
|
+
floatingToolbar: (0, _toolbar.getToolbarConfig)(defaultGetEditorContainerWidth, editorAnalyticsAPI, (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags, function () {
|
|
344
339
|
return editorViewRef.current;
|
|
345
340
|
})((0, _createPluginConfig.pluginConfig)(options === null || options === void 0 ? void 0 : options.tableOptions))
|
|
346
341
|
}
|
|
@@ -284,7 +284,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
284
284
|
* We no longer use `containerWidth` as a variable to determine an update for table resizing (avoids unnecessary updates).
|
|
285
285
|
* Instead we use the resize event to only trigger updates when necessary.
|
|
286
286
|
*/
|
|
287
|
-
|
|
287
|
+
if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
|
|
288
|
+
window.addEventListener('resize', this.handleWindowResizeDebounced);
|
|
289
|
+
}
|
|
288
290
|
this.handleTableResizingDebounced();
|
|
289
291
|
}
|
|
290
292
|
var currentStickyState = _stickyHeaders.pluginKey.getState(this.props.view.state);
|
|
@@ -303,8 +305,10 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
303
305
|
this.scaleTableDebounced.cancel();
|
|
304
306
|
this.handleTableResizingDebounced.cancel();
|
|
305
307
|
this.handleAutoSizeDebounced.cancel();
|
|
306
|
-
|
|
307
|
-
|
|
308
|
+
if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
|
|
309
|
+
this.handleWindowResizeDebounced.cancel();
|
|
310
|
+
}
|
|
311
|
+
if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') && this.props.allowColumnResizing) {
|
|
308
312
|
window.removeEventListener('resize', this.handleWindowResizeDebounced);
|
|
309
313
|
}
|
|
310
314
|
if (this.overflowShadowsObserver) {
|
|
@@ -11,6 +11,7 @@ var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
|
11
11
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
12
12
|
var _types = require("../types");
|
|
13
13
|
var _TableResizer = require("./TableResizer");
|
|
14
|
+
var _utils = require("../pm-plugins/table-resizing/utils");
|
|
14
15
|
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); }
|
|
15
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
17
|
var getMarginLeft = function getMarginLeft(_ref) {
|
|
@@ -26,17 +27,13 @@ var getMarginLeft = function getMarginLeft(_ref) {
|
|
|
26
27
|
return marginLeft;
|
|
27
28
|
};
|
|
28
29
|
var InnerContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
width = _ref2.width,
|
|
30
|
+
var className = _ref2.className,
|
|
31
|
+
style = _ref2.style,
|
|
32
32
|
node = _ref2.node,
|
|
33
33
|
children = _ref2.children;
|
|
34
34
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
35
35
|
ref: ref,
|
|
36
|
-
style:
|
|
37
|
-
width: width,
|
|
38
|
-
marginLeft: marginLeft
|
|
39
|
-
},
|
|
36
|
+
style: style,
|
|
40
37
|
className: className,
|
|
41
38
|
"data-number-column": node.attrs.isNumberColumnEnabled,
|
|
42
39
|
"data-layout": node.attrs.layout,
|
|
@@ -49,6 +46,7 @@ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
|
|
|
49
46
|
className = _ref3.className,
|
|
50
47
|
node = _ref3.node,
|
|
51
48
|
lineLength = _ref3.lineLength,
|
|
49
|
+
containerWidth = _ref3.containerWidth,
|
|
52
50
|
editorView = _ref3.editorView,
|
|
53
51
|
getPos = _ref3.getPos,
|
|
54
52
|
tableRef = _ref3.tableRef;
|
|
@@ -58,19 +56,24 @@ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
|
|
|
58
56
|
if (!containerRef.current || !innerContainerRef.current) {
|
|
59
57
|
return;
|
|
60
58
|
}
|
|
61
|
-
innerContainerRef.current.style.width = "".concat(width, "px");
|
|
62
59
|
var marginLeft = getMarginLeft({
|
|
63
60
|
lineLength: lineLength,
|
|
64
61
|
tableWidth: width
|
|
65
62
|
});
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
if (marginLeft) {
|
|
64
|
+
containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
|
|
65
|
+
}
|
|
68
66
|
}, [lineLength]);
|
|
69
|
-
var
|
|
67
|
+
var tableWidth = (0, _nodeWidth.getTableContainerWidth)(node);
|
|
68
|
+
|
|
69
|
+
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
70
|
+
var responsiveContainerWidth = containerWidth - 76;
|
|
71
|
+
var width = Math.min(tableWidth, responsiveContainerWidth);
|
|
70
72
|
var marginLeft = getMarginLeft({
|
|
71
73
|
lineLength: lineLength,
|
|
72
74
|
tableWidth: width
|
|
73
75
|
});
|
|
76
|
+
var maxResizerWidth = Math.min(responsiveContainerWidth, _utils.TABLE_MAX_WIDTH);
|
|
74
77
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
75
78
|
style: {
|
|
76
79
|
marginLeft: marginLeft,
|
|
@@ -80,6 +83,7 @@ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
|
|
|
80
83
|
ref: containerRef
|
|
81
84
|
}, /*#__PURE__*/_react.default.createElement(_TableResizer.TableResizer, {
|
|
82
85
|
width: width,
|
|
86
|
+
maxWidth: maxResizerWidth,
|
|
83
87
|
updateWidth: updateWidth,
|
|
84
88
|
editorView: editorView,
|
|
85
89
|
getPos: getPos,
|
|
@@ -88,9 +92,7 @@ var ResizableTableContainer = function ResizableTableContainer(_ref3) {
|
|
|
88
92
|
}, /*#__PURE__*/_react.default.createElement(InnerContainer, {
|
|
89
93
|
ref: innerContainerRef,
|
|
90
94
|
className: className,
|
|
91
|
-
node: node
|
|
92
|
-
width: width,
|
|
93
|
-
marginLeft: 0
|
|
95
|
+
node: node
|
|
94
96
|
}, children)));
|
|
95
97
|
};
|
|
96
98
|
exports.ResizableTableContainer = ResizableTableContainer;
|
|
@@ -121,11 +123,13 @@ var TableContainer = function TableContainer(_ref4) {
|
|
|
121
123
|
return /*#__PURE__*/_react.default.createElement(InnerContainer, {
|
|
122
124
|
node: node,
|
|
123
125
|
className: className,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
style: {
|
|
127
|
+
width: tableWidth,
|
|
128
|
+
marginLeft: getMarginLeft({
|
|
129
|
+
lineLength: lineLength,
|
|
130
|
+
tableWidth: tableWidth
|
|
131
|
+
})
|
|
132
|
+
}
|
|
129
133
|
}, children);
|
|
130
134
|
};
|
|
131
135
|
exports.TableContainer = TableContainer;
|
|
@@ -18,6 +18,7 @@ var handles = {
|
|
|
18
18
|
var TableResizer = function TableResizer(_ref) {
|
|
19
19
|
var children = _ref.children,
|
|
20
20
|
width = _ref.width,
|
|
21
|
+
maxWidth = _ref.maxWidth,
|
|
21
22
|
updateWidth = _ref.updateWidth,
|
|
22
23
|
editorView = _ref.editorView,
|
|
23
24
|
getPos = _ref.getPos,
|
|
@@ -70,7 +71,7 @@ var TableResizer = function TableResizer(_ref) {
|
|
|
70
71
|
},
|
|
71
72
|
resizeRatio: 2,
|
|
72
73
|
minWidth: minColumnWidth,
|
|
73
|
-
maxWidth:
|
|
74
|
+
maxWidth: maxWidth
|
|
74
75
|
}, children);
|
|
75
76
|
};
|
|
76
77
|
exports.TableResizer = TableResizer;
|
|
@@ -26,15 +26,19 @@ var _tableResizing = require("../pm-plugins/table-resizing");
|
|
|
26
26
|
var _utils = require("../pm-plugins/table-resizing/utils");
|
|
27
27
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
28
28
|
var _TableComponent = _interopRequireDefault(require("./TableComponent"));
|
|
29
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
30
|
+
var _nodeWidth = require("@atlaskit/editor-common/node-width");
|
|
29
31
|
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); }; }
|
|
30
32
|
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; } }
|
|
31
33
|
var tableAttributes = function tableAttributes(node) {
|
|
34
|
+
var style = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? "width: ".concat((0, _nodeWidth.getTableContainerWidth)(node), "px") : undefined;
|
|
32
35
|
return {
|
|
33
36
|
'data-number-column': node.attrs.isNumberColumnEnabled,
|
|
34
37
|
'data-layout': node.attrs.layout,
|
|
35
38
|
'data-autosize': node.attrs.__autoSize,
|
|
36
39
|
'data-table-local-id': node.attrs.localId || '',
|
|
37
|
-
'data-table-width': node.attrs.width
|
|
40
|
+
'data-table-width': node.attrs.width,
|
|
41
|
+
style: style
|
|
38
42
|
};
|
|
39
43
|
};
|
|
40
44
|
var toDOM = function toDOM(node, props) {
|
|
@@ -10,6 +10,7 @@ exports.scaleWithParent = void 0;
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
12
12
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
13
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
14
|
var _utils = require("../../../utils");
|
|
14
15
|
var _misc = require("../utils/misc");
|
|
15
16
|
var _resizeLogic = require("../utils/resize-logic");
|
|
@@ -112,7 +113,13 @@ var previewScaleTable = function previewScaleTable(tableRef, options, domAtPos)
|
|
|
112
113
|
var node = options.node,
|
|
113
114
|
start = options.start,
|
|
114
115
|
parentWidth = options.parentWidth;
|
|
115
|
-
if (!tableRef
|
|
116
|
+
if (!tableRef) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') && parentWidth) {
|
|
120
|
+
tableRef.style.width = "".concat(parentWidth, "px");
|
|
121
|
+
}
|
|
122
|
+
if (!(0, _colgroup.hasTableBeenResized)(node)) {
|
|
116
123
|
return;
|
|
117
124
|
}
|
|
118
125
|
var resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
|
package/dist/cjs/version.json
CHANGED
|
@@ -31,6 +31,7 @@ import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
|
31
31
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
32
32
|
const defaultGetEditorFeatureFlags = () => ({});
|
|
33
33
|
const tablesPlugin = (options, api) => {
|
|
34
|
+
var _api$dependencies$ana;
|
|
34
35
|
const editorViewRef = {
|
|
35
36
|
current: null
|
|
36
37
|
};
|
|
@@ -41,6 +42,7 @@ const tablesPlugin = (options, api) => {
|
|
|
41
42
|
};
|
|
42
43
|
return (_api$dependencies$wid = api === null || api === void 0 ? void 0 : api.dependencies.width.sharedState.currentState()) !== null && _api$dependencies$wid !== void 0 ? _api$dependencies$wid : defaultState;
|
|
43
44
|
};
|
|
45
|
+
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions;
|
|
44
46
|
return {
|
|
45
47
|
name: 'table',
|
|
46
48
|
actions: {
|
|
@@ -85,17 +87,13 @@ const tablesPlugin = (options, api) => {
|
|
|
85
87
|
portalProviderAPI,
|
|
86
88
|
eventDispatcher
|
|
87
89
|
}) => {
|
|
88
|
-
var _api$dependencies$ana;
|
|
89
90
|
const {
|
|
90
91
|
fullWidthEnabled,
|
|
91
92
|
wasFullWidthEnabled,
|
|
92
93
|
breakoutEnabled,
|
|
93
94
|
tableOptions,
|
|
94
|
-
editorAnalyticsAPI,
|
|
95
95
|
getEditorFeatureFlags
|
|
96
|
-
} = options || {
|
|
97
|
-
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions
|
|
98
|
-
};
|
|
96
|
+
} = options || {};
|
|
99
97
|
return createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig(tableOptions), defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, breakoutEnabled, fullWidthEnabled, wasFullWidthEnabled, editorAnalyticsAPI);
|
|
100
98
|
}
|
|
101
99
|
}, {
|
|
@@ -106,7 +104,6 @@ const tablesPlugin = (options, api) => {
|
|
|
106
104
|
const {
|
|
107
105
|
fullWidthEnabled,
|
|
108
106
|
tableOptions,
|
|
109
|
-
editorAnalyticsAPI,
|
|
110
107
|
getEditorFeatureFlags
|
|
111
108
|
} = options || {};
|
|
112
109
|
const {
|
|
@@ -124,7 +121,7 @@ const tablesPlugin = (options, api) => {
|
|
|
124
121
|
// plugin as it is currently swallowing backspace events inside tables
|
|
125
122
|
{
|
|
126
123
|
name: 'tableKeymap',
|
|
127
|
-
plugin: () => keymapPlugin(defaultGetEditorContainerWidth,
|
|
124
|
+
plugin: () => keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI)
|
|
128
125
|
}, {
|
|
129
126
|
name: 'tableSelectionKeymap',
|
|
130
127
|
plugin: () => tableSelectionKeymapPlugin(options === null || options === void 0 ? void 0 : options.editorSelectionAPI)
|
|
@@ -136,8 +133,7 @@ const tablesPlugin = (options, api) => {
|
|
|
136
133
|
tr,
|
|
137
134
|
reason
|
|
138
135
|
}) => {
|
|
139
|
-
|
|
140
|
-
options === null || options === void 0 ? void 0 : (_options$editorAnalyt = options.editorAnalyticsAPI) === null || _options$editorAnalyt === void 0 ? void 0 : _options$editorAnalyt.attachAnalyticsEvent({
|
|
136
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
141
137
|
action: TABLE_ACTION.FIXED,
|
|
142
138
|
actionSubject: ACTION_SUBJECT.TABLE,
|
|
143
139
|
actionSubjectId: null,
|
|
@@ -245,7 +241,7 @@ const tablesPlugin = (options, api) => {
|
|
|
245
241
|
layout: layout,
|
|
246
242
|
isResizing: !!resizingPluginState && !!resizingPluginState.dragging,
|
|
247
243
|
stickyHeader: stickyHeader,
|
|
248
|
-
editorAnalyticsAPI:
|
|
244
|
+
editorAnalyticsAPI: editorAnalyticsAPI
|
|
249
245
|
}) : null;
|
|
250
246
|
return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && tableRef && !isDragging && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
|
|
251
247
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
@@ -272,7 +268,7 @@ const tablesPlugin = (options, api) => {
|
|
|
272
268
|
scrollableElement: popupsScrollableElement,
|
|
273
269
|
hasStickyHeaders: stickyHeader && stickyHeader.sticky,
|
|
274
270
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
275
|
-
editorAnalyticsAPI:
|
|
271
|
+
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
276
272
|
getEditorContainerWidth: defaultGetEditorContainerWidth
|
|
277
273
|
}), /*#__PURE__*/React.createElement(FloatingContextualMenu, {
|
|
278
274
|
editorView: editorView,
|
|
@@ -281,7 +277,7 @@ const tablesPlugin = (options, api) => {
|
|
|
281
277
|
targetCellPosition: targetCellPosition,
|
|
282
278
|
isOpen: Boolean(isContextualMenuOpen),
|
|
283
279
|
pluginConfig: pluginConfig,
|
|
284
|
-
editorAnalyticsAPI:
|
|
280
|
+
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
285
281
|
getEditorContainerWidth: defaultGetEditorContainerWidth,
|
|
286
282
|
getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
|
|
287
283
|
}), allowControls && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
|
|
@@ -293,7 +289,7 @@ const tablesPlugin = (options, api) => {
|
|
|
293
289
|
scrollableElement: popupsScrollableElement,
|
|
294
290
|
stickyHeaders: stickyHeader,
|
|
295
291
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
296
|
-
editorAnalyticsAPI:
|
|
292
|
+
editorAnalyticsAPI: editorAnalyticsAPI
|
|
297
293
|
}), LayoutContent);
|
|
298
294
|
}
|
|
299
295
|
}));
|
|
@@ -310,11 +306,10 @@ const tablesPlugin = (options, api) => {
|
|
|
310
306
|
keyshortcut: tooltip(toggleTable),
|
|
311
307
|
icon: () => /*#__PURE__*/React.createElement(IconTable, null),
|
|
312
308
|
action(insert, state) {
|
|
313
|
-
var _options$editorAnalyt2;
|
|
314
309
|
const tr = insert(createTable({
|
|
315
310
|
schema: state.schema
|
|
316
311
|
}));
|
|
317
|
-
|
|
312
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
318
313
|
action: ACTION.INSERTED,
|
|
319
314
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
320
315
|
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
@@ -326,7 +321,7 @@ const tablesPlugin = (options, api) => {
|
|
|
326
321
|
return tr;
|
|
327
322
|
}
|
|
328
323
|
}],
|
|
329
|
-
floatingToolbar: getToolbarConfig(defaultGetEditorContainerWidth,
|
|
324
|
+
floatingToolbar: getToolbarConfig(defaultGetEditorContainerWidth, editorAnalyticsAPI, (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags, () => editorViewRef.current)(pluginConfig(options === null || options === void 0 ? void 0 : options.tableOptions))
|
|
330
325
|
}
|
|
331
326
|
};
|
|
332
327
|
};
|
|
@@ -281,7 +281,9 @@ class TableComponent extends React.Component {
|
|
|
281
281
|
* We no longer use `containerWidth` as a variable to determine an update for table resizing (avoids unnecessary updates).
|
|
282
282
|
* Instead we use the resize event to only trigger updates when necessary.
|
|
283
283
|
*/
|
|
284
|
-
|
|
284
|
+
if (!getBooleanFF('platform.editor.custom-table-width')) {
|
|
285
|
+
window.addEventListener('resize', this.handleWindowResizeDebounced);
|
|
286
|
+
}
|
|
285
287
|
this.handleTableResizingDebounced();
|
|
286
288
|
}
|
|
287
289
|
const currentStickyState = stickyHeadersPluginKey.getState(this.props.view.state);
|
|
@@ -298,8 +300,10 @@ class TableComponent extends React.Component {
|
|
|
298
300
|
this.scaleTableDebounced.cancel();
|
|
299
301
|
this.handleTableResizingDebounced.cancel();
|
|
300
302
|
this.handleAutoSizeDebounced.cancel();
|
|
301
|
-
|
|
302
|
-
|
|
303
|
+
if (!getBooleanFF('platform.editor.custom-table-width')) {
|
|
304
|
+
this.handleWindowResizeDebounced.cancel();
|
|
305
|
+
}
|
|
306
|
+
if (!getBooleanFF('platform.editor.custom-table-width') && this.props.allowColumnResizing) {
|
|
303
307
|
window.removeEventListener('resize', this.handleWindowResizeDebounced);
|
|
304
308
|
}
|
|
305
309
|
if (this.overflowShadowsObserver) {
|
|
@@ -4,6 +4,7 @@ import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
|
4
4
|
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
5
5
|
import { TableCssClassName as ClassName } from '../types';
|
|
6
6
|
import { TableResizer } from './TableResizer';
|
|
7
|
+
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
7
8
|
const getMarginLeft = ({
|
|
8
9
|
lineLength,
|
|
9
10
|
tableWidth
|
|
@@ -18,18 +19,14 @@ const getMarginLeft = ({
|
|
|
18
19
|
return marginLeft;
|
|
19
20
|
};
|
|
20
21
|
export const InnerContainer = /*#__PURE__*/forwardRef(({
|
|
21
|
-
marginLeft,
|
|
22
22
|
className,
|
|
23
|
-
|
|
23
|
+
style,
|
|
24
24
|
node,
|
|
25
25
|
children
|
|
26
26
|
}, ref) => {
|
|
27
27
|
return /*#__PURE__*/React.createElement("div", {
|
|
28
28
|
ref: ref,
|
|
29
|
-
style:
|
|
30
|
-
width,
|
|
31
|
-
marginLeft
|
|
32
|
-
},
|
|
29
|
+
style: style,
|
|
33
30
|
className: className,
|
|
34
31
|
"data-number-column": node.attrs.isNumberColumnEnabled,
|
|
35
32
|
"data-layout": node.attrs.layout,
|
|
@@ -41,6 +38,7 @@ export const ResizableTableContainer = ({
|
|
|
41
38
|
className,
|
|
42
39
|
node,
|
|
43
40
|
lineLength,
|
|
41
|
+
containerWidth,
|
|
44
42
|
editorView,
|
|
45
43
|
getPos,
|
|
46
44
|
tableRef
|
|
@@ -51,19 +49,24 @@ export const ResizableTableContainer = ({
|
|
|
51
49
|
if (!containerRef.current || !innerContainerRef.current) {
|
|
52
50
|
return;
|
|
53
51
|
}
|
|
54
|
-
innerContainerRef.current.style.width = `${width}px`;
|
|
55
52
|
const marginLeft = getMarginLeft({
|
|
56
53
|
lineLength,
|
|
57
54
|
tableWidth: width
|
|
58
55
|
});
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
if (marginLeft) {
|
|
57
|
+
containerRef.current.style.marginLeft = `${marginLeft}px`;
|
|
58
|
+
}
|
|
61
59
|
}, [lineLength]);
|
|
62
|
-
const
|
|
60
|
+
const tableWidth = getTableContainerWidth(node);
|
|
61
|
+
|
|
62
|
+
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
63
|
+
const responsiveContainerWidth = containerWidth - 76;
|
|
64
|
+
const width = Math.min(tableWidth, responsiveContainerWidth);
|
|
63
65
|
const marginLeft = getMarginLeft({
|
|
64
66
|
lineLength,
|
|
65
67
|
tableWidth: width
|
|
66
68
|
});
|
|
69
|
+
const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
|
|
67
70
|
return /*#__PURE__*/React.createElement("div", {
|
|
68
71
|
style: {
|
|
69
72
|
marginLeft,
|
|
@@ -73,6 +76,7 @@ export const ResizableTableContainer = ({
|
|
|
73
76
|
ref: containerRef
|
|
74
77
|
}, /*#__PURE__*/React.createElement(TableResizer, {
|
|
75
78
|
width: width,
|
|
79
|
+
maxWidth: maxResizerWidth,
|
|
76
80
|
updateWidth: updateWidth,
|
|
77
81
|
editorView: editorView,
|
|
78
82
|
getPos: getPos,
|
|
@@ -81,9 +85,7 @@ export const ResizableTableContainer = ({
|
|
|
81
85
|
}, /*#__PURE__*/React.createElement(InnerContainer, {
|
|
82
86
|
ref: innerContainerRef,
|
|
83
87
|
className: className,
|
|
84
|
-
node: node
|
|
85
|
-
width: width,
|
|
86
|
-
marginLeft: 0
|
|
88
|
+
node: node
|
|
87
89
|
}, children)));
|
|
88
90
|
};
|
|
89
91
|
export const TableContainer = ({
|
|
@@ -115,10 +117,12 @@ export const TableContainer = ({
|
|
|
115
117
|
return /*#__PURE__*/React.createElement(InnerContainer, {
|
|
116
118
|
node: node,
|
|
117
119
|
className: className,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
style: {
|
|
121
|
+
width: tableWidth,
|
|
122
|
+
marginLeft: getMarginLeft({
|
|
123
|
+
lineLength: lineLength,
|
|
124
|
+
tableWidth
|
|
125
|
+
})
|
|
126
|
+
}
|
|
123
127
|
}, children);
|
|
124
128
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import rafSchd from 'raf-schd';
|
|
3
3
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
4
|
-
import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH
|
|
4
|
+
import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
5
5
|
const handles = {
|
|
6
6
|
right: true
|
|
7
7
|
};
|
|
8
8
|
export const TableResizer = ({
|
|
9
9
|
children,
|
|
10
10
|
width,
|
|
11
|
+
maxWidth,
|
|
11
12
|
updateWidth,
|
|
12
13
|
editorView,
|
|
13
14
|
getPos,
|
|
@@ -62,6 +63,6 @@ export const TableResizer = ({
|
|
|
62
63
|
},
|
|
63
64
|
resizeRatio: 2,
|
|
64
65
|
minWidth: minColumnWidth,
|
|
65
|
-
maxWidth:
|
|
66
|
+
maxWidth: maxWidth
|
|
66
67
|
}, children);
|
|
67
68
|
};
|
|
@@ -10,13 +10,17 @@ import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizin
|
|
|
10
10
|
import { generateColgroup } from '../pm-plugins/table-resizing/utils';
|
|
11
11
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
12
12
|
import TableComponent from './TableComponent';
|
|
13
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
13
15
|
const tableAttributes = node => {
|
|
16
|
+
const style = getBooleanFF('platform.editor.custom-table-width') ? `width: ${getTableContainerWidth(node)}px` : undefined;
|
|
14
17
|
return {
|
|
15
18
|
'data-number-column': node.attrs.isNumberColumnEnabled,
|
|
16
19
|
'data-layout': node.attrs.layout,
|
|
17
20
|
'data-autosize': node.attrs.__autoSize,
|
|
18
21
|
'data-table-local-id': node.attrs.localId || '',
|
|
19
|
-
'data-table-width': node.attrs.width
|
|
22
|
+
'data-table-width': node.attrs.width,
|
|
23
|
+
style
|
|
20
24
|
};
|
|
21
25
|
};
|
|
22
26
|
const toDOM = (node, props) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
2
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
3
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { getTableWidth } from '../../../utils';
|
|
4
5
|
import { getLayoutSize } from '../utils/misc';
|
|
5
6
|
import { reduceSpace } from '../utils/resize-logic';
|
|
@@ -106,7 +107,13 @@ export const previewScaleTable = (tableRef, options, domAtPos) => {
|
|
|
106
107
|
start,
|
|
107
108
|
parentWidth
|
|
108
109
|
} = options;
|
|
109
|
-
if (!tableRef
|
|
110
|
+
if (!tableRef) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (getBooleanFF('platform.editor.custom-table-width') && parentWidth) {
|
|
114
|
+
tableRef.style.width = `${parentWidth}px`;
|
|
115
|
+
}
|
|
116
|
+
if (!hasTableBeenResized(node)) {
|
|
110
117
|
return;
|
|
111
118
|
}
|
|
112
119
|
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos) : scale(tableRef, options, domAtPos);
|