@atlaskit/editor-plugin-table 7.12.2 → 7.12.3
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 +8 -0
- package/dist/cjs/nodeviews/TableResizer.js +10 -4
- package/dist/cjs/plugin.js +15 -0
- package/dist/cjs/pm-plugins/table-width.js +16 -11
- package/dist/cjs/toolbar.js +9 -56
- package/dist/cjs/ui/FloatingToolbarLabel/FloatingToolbarLabel.js +28 -0
- package/dist/cjs/ui/TableFullWidthLabel/index.js +18 -5
- package/dist/es2019/nodeviews/TableResizer.js +10 -4
- package/dist/es2019/plugin.js +15 -0
- package/dist/es2019/pm-plugins/table-width.js +16 -7
- package/dist/es2019/toolbar.js +0 -50
- package/dist/es2019/ui/FloatingToolbarLabel/FloatingToolbarLabel.js +23 -0
- package/dist/es2019/ui/TableFullWidthLabel/index.js +18 -5
- package/dist/esm/nodeviews/TableResizer.js +10 -4
- package/dist/esm/plugin.js +15 -0
- package/dist/esm/pm-plugins/table-width.js +14 -8
- package/dist/esm/toolbar.js +9 -56
- package/dist/esm/ui/FloatingToolbarLabel/FloatingToolbarLabel.js +21 -0
- package/dist/esm/ui/TableFullWidthLabel/index.js +18 -5
- package/dist/types/pm-plugins/table-width.d.ts +4 -0
- package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/table-width.d.ts +4 -0
- package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +15 -0
- package/package.json +1 -1
- package/src/nodeviews/TableResizer.tsx +18 -3
- package/src/plugin.tsx +23 -0
- package/src/pm-plugins/table-width.ts +15 -4
- package/src/toolbar.tsx +0 -57
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +36 -0
- package/src/ui/TableFullWidthLabel/index.tsx +19 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.12.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#97034](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/97034)
|
|
8
|
+
[`96595e52fb33`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/96595e52fb33) -
|
|
9
|
+
ED-22627: Fixed full-width label no show when selection outside table
|
|
10
|
+
|
|
3
11
|
## 7.12.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -149,7 +149,9 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
149
149
|
displayGapCursor(true);
|
|
150
150
|
displayGuideline([]);
|
|
151
151
|
_tr.setMeta(_tableWidth.pluginKey, {
|
|
152
|
-
resizing: false
|
|
152
|
+
resizing: false,
|
|
153
|
+
tableLocalId: '',
|
|
154
|
+
tableRef: null
|
|
153
155
|
});
|
|
154
156
|
dispatch(_tr);
|
|
155
157
|
}
|
|
@@ -162,7 +164,9 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
162
164
|
tr = editorView.state.tr;
|
|
163
165
|
displayGapCursor(false);
|
|
164
166
|
tr.setMeta(_tableWidth.pluginKey, {
|
|
165
|
-
resizing: true
|
|
167
|
+
resizing: true,
|
|
168
|
+
tableLocalId: node.attrs.localId,
|
|
169
|
+
tableRef: tableRef
|
|
166
170
|
});
|
|
167
171
|
tr.setMeta(_tableAnalytics.META_KEYS.OVERFLOW_TRIGGER, {
|
|
168
172
|
name: _analytics.TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
|
|
@@ -173,7 +177,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
173
177
|
if (onResizeStart) {
|
|
174
178
|
onResizeStart();
|
|
175
179
|
}
|
|
176
|
-
}, [startMeasure, editorView, displayGapCursor, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
180
|
+
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
177
181
|
var handleResize = (0, _react.useCallback)(function (originalState, delta) {
|
|
178
182
|
var _node$attrs$localId, _node$attrs;
|
|
179
183
|
countFrames();
|
|
@@ -222,7 +226,9 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
222
226
|
var currentTableNodeLocalId = (_node$attrs$localId2 = node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.localId) !== null && _node$attrs$localId2 !== void 0 ? _node$attrs$localId2 : '';
|
|
223
227
|
newWidth = widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId] ? _utils3.TABLE_MAX_WIDTH : newWidth;
|
|
224
228
|
var tr = state.tr.setMeta(_tableWidth.pluginKey, {
|
|
225
|
-
resizing: false
|
|
229
|
+
resizing: false,
|
|
230
|
+
tableLocalId: '',
|
|
231
|
+
tableRef: null
|
|
226
232
|
});
|
|
227
233
|
var frameRateSamples = endMeasure();
|
|
228
234
|
if (frameRateSamples.length > 0) {
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -15,6 +15,7 @@ var _messages = require("@atlaskit/editor-common/messages");
|
|
|
15
15
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
16
16
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
17
17
|
var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
|
|
18
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
18
19
|
var _pmPlugins = require("@atlaskit/editor-tables/pm-plugins");
|
|
19
20
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
20
21
|
var _insert = require("./commands/insert");
|
|
@@ -41,6 +42,8 @@ var _FloatingContextualMenu = _interopRequireDefault(require("./ui/FloatingConte
|
|
|
41
42
|
var _FloatingDeleteButton = _interopRequireDefault(require("./ui/FloatingDeleteButton"));
|
|
42
43
|
var _FloatingDragMenu = _interopRequireDefault(require("./ui/FloatingDragMenu"));
|
|
43
44
|
var _FloatingInsertButton = _interopRequireDefault(require("./ui/FloatingInsertButton"));
|
|
45
|
+
var _FloatingToolbarLabel = require("./ui/FloatingToolbarLabel/FloatingToolbarLabel");
|
|
46
|
+
var _TableFullWidthLabel = require("./ui/TableFullWidthLabel");
|
|
44
47
|
var _utils2 = require("./utils");
|
|
45
48
|
var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
|
|
46
49
|
return {};
|
|
@@ -319,7 +322,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
319
322
|
dragAndDropState = _ref17.dragAndDropState;
|
|
320
323
|
var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
321
324
|
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
325
|
+
var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
|
|
326
|
+
var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
|
|
322
327
|
var isResizing = isColumnResizing || isTableResizing;
|
|
328
|
+
var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
|
|
323
329
|
var _ref18 = tablePluginState,
|
|
324
330
|
tableNode = _ref18.tableNode,
|
|
325
331
|
tablePos = _ref18.tablePos,
|
|
@@ -397,6 +403,15 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
397
403
|
stickyHeaders: stickyHeader,
|
|
398
404
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
399
405
|
editorAnalyticsAPI: editorAnalyticsAPI
|
|
406
|
+
}), (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/_react.default.createElement(_FloatingToolbarLabel.FloatingToolbarLabel, {
|
|
407
|
+
target: resizingTableRef,
|
|
408
|
+
content: /*#__PURE__*/_react.default.createElement(_TableFullWidthLabel.FullWidthDisplay, null),
|
|
409
|
+
alignX: 'center',
|
|
410
|
+
alignY: 'bottom',
|
|
411
|
+
stick: true,
|
|
412
|
+
forcePlacement: true,
|
|
413
|
+
zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex,
|
|
414
|
+
offset: [0, 10]
|
|
400
415
|
}));
|
|
401
416
|
}
|
|
402
417
|
}));
|
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.pluginKey = exports.createPlugin = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _steps = require("@atlaskit/adf-schema/steps");
|
|
11
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
12
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
@@ -16,13 +16,12 @@ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
|
16
16
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
17
17
|
var _utils2 = require("./table-resizing/utils");
|
|
18
18
|
var _excluded = ["width"];
|
|
19
|
-
|
|
19
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
|
|
20
21
|
* A plugin for handle table custom widths
|
|
21
22
|
* Has login to scan the document, add width value to table's width attribute when necessary
|
|
22
23
|
* Also holds resizing state to hide / show table controls
|
|
23
24
|
*/
|
|
24
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
25
|
var pluginKey = exports.pluginKey = new _state.PluginKey('tableWidthPlugin');
|
|
27
26
|
var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled) {
|
|
28
27
|
return new _safePlugin.SafePlugin({
|
|
@@ -30,17 +29,23 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
|
|
|
30
29
|
state: {
|
|
31
30
|
init: function init() {
|
|
32
31
|
return {
|
|
33
|
-
resizing: false
|
|
32
|
+
resizing: false,
|
|
33
|
+
tableLocalId: '',
|
|
34
|
+
tableRef: null
|
|
34
35
|
};
|
|
35
36
|
},
|
|
36
37
|
apply: function apply(tr, pluginState) {
|
|
37
38
|
var meta = tr.getMeta(pluginKey);
|
|
38
|
-
if (meta
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
if (meta) {
|
|
40
|
+
var keys = Object.keys(meta);
|
|
41
|
+
var changed = keys.some(function (key) {
|
|
42
|
+
return pluginState[key] !== meta[key];
|
|
43
|
+
});
|
|
44
|
+
if (changed) {
|
|
45
|
+
var newState = _objectSpread(_objectSpread({}, pluginState), meta);
|
|
46
|
+
dispatch(pluginKey, newState);
|
|
47
|
+
return newState;
|
|
48
|
+
}
|
|
44
49
|
}
|
|
45
50
|
return pluginState;
|
|
46
51
|
}
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -33,7 +33,6 @@ var _tableWidth = require("./pm-plugins/table-width");
|
|
|
33
33
|
var _transforms = require("./transforms");
|
|
34
34
|
var _types = require("./types");
|
|
35
35
|
var _icons = require("./ui/icons");
|
|
36
|
-
var _TableFullWidthLabel = require("./ui/TableFullWidthLabel");
|
|
37
36
|
var _utils4 = require("./utils");
|
|
38
37
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
39
38
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -316,7 +315,6 @@ var getClosestSelectionOrTableRect = exports.getClosestSelectionOrTableRect = fu
|
|
|
316
315
|
var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, getEditorView, options) {
|
|
317
316
|
return function (config) {
|
|
318
317
|
return function (state, intl) {
|
|
319
|
-
var _tableObject$node$att, _tableObject$node;
|
|
320
318
|
var tableObject = (0, _utils3.findTable)(state.selection);
|
|
321
319
|
var pluginState = (0, _pluginFactory.getPluginState)(state);
|
|
322
320
|
var resizeState = _tableResizing.pluginKey.getState(state);
|
|
@@ -324,53 +322,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
|
|
|
324
322
|
|
|
325
323
|
// We don't want to show floating toolbar while resizing the table
|
|
326
324
|
var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
327
|
-
var widthToWidest = pluginState.widthToWidest;
|
|
328
|
-
var currentTableNodeLocalId = (_tableObject$node$att = tableObject === null || tableObject === void 0 || (_tableObject$node = tableObject.node) === null || _tableObject$node === void 0 || (_tableObject$node = _tableObject$node.attrs) === null || _tableObject$node === void 0 ? void 0 : _tableObject$node.localId) !== null && _tableObject$node$att !== void 0 ? _tableObject$node$att : '';
|
|
329
|
-
if (options !== null && options !== void 0 && options.isTableScalingEnabled && isWidthResizing && widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId]) {
|
|
330
|
-
var _getEditorFeatureFlag = getEditorFeatureFlags(),
|
|
331
|
-
stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
|
|
332
|
-
var nodeType = state.schema.nodes.table;
|
|
333
|
-
var getDomRef = function getDomRef(editorView) {
|
|
334
|
-
var element;
|
|
335
|
-
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
336
|
-
var parent = (0, _utils2.findParentDomRefOfType)(nodeType, domAtPos)(state.selection);
|
|
337
|
-
if (parent) {
|
|
338
|
-
var tableRef = parent.querySelector('table') || undefined;
|
|
339
|
-
if (tableRef) {
|
|
340
|
-
element = (0, _utils.closestElement)(tableRef, ".".concat(_types.TableCssClassName.TABLE_NODE_WRAPPER)) || undefined;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return element;
|
|
344
|
-
};
|
|
345
|
-
var fullWidthLabel = {
|
|
346
|
-
id: 'editor.table.fullWidthLabel',
|
|
347
|
-
type: 'custom',
|
|
348
|
-
fallback: [],
|
|
349
|
-
render: function render() {
|
|
350
|
-
return (0, _react.jsx)(_TableFullWidthLabel.FullWidthDisplay, {
|
|
351
|
-
key: 'full-width-label'
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
return {
|
|
356
|
-
title: 'Table floating label',
|
|
357
|
-
getDomRef: getDomRef,
|
|
358
|
-
nodeType: nodeType,
|
|
359
|
-
key: 'full-width-label',
|
|
360
|
-
offset: [0, 18],
|
|
361
|
-
absoluteOffset: stickyScrollbar ? {
|
|
362
|
-
top: -6
|
|
363
|
-
} : {
|
|
364
|
-
top: 0
|
|
365
|
-
},
|
|
366
|
-
zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex + 1,
|
|
367
|
-
// Place the context menu slightly above the others
|
|
368
|
-
items: [fullWidthLabel],
|
|
369
|
-
scrollable: true
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
325
|
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
373
|
-
var
|
|
326
|
+
var nodeType = state.schema.nodes.table;
|
|
374
327
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
375
328
|
var cellItems;
|
|
376
329
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
@@ -402,10 +355,10 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
|
|
|
402
355
|
};
|
|
403
356
|
};
|
|
404
357
|
}
|
|
405
|
-
var
|
|
358
|
+
var getDomRef = function getDomRef(editorView) {
|
|
406
359
|
var element;
|
|
407
360
|
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
408
|
-
var parent = (0, _utils2.findParentDomRefOfType)(
|
|
361
|
+
var parent = (0, _utils2.findParentDomRefOfType)(nodeType, domAtPos)(state.selection);
|
|
409
362
|
if (parent) {
|
|
410
363
|
var tableRef = parent.querySelector('table') || undefined;
|
|
411
364
|
if (tableRef) {
|
|
@@ -414,14 +367,14 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
|
|
|
414
367
|
}
|
|
415
368
|
return element;
|
|
416
369
|
};
|
|
417
|
-
var
|
|
418
|
-
|
|
370
|
+
var _getEditorFeatureFlag = getEditorFeatureFlags(),
|
|
371
|
+
stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
|
|
419
372
|
return {
|
|
420
373
|
title: 'Table floating controls',
|
|
421
|
-
getDomRef:
|
|
422
|
-
nodeType:
|
|
374
|
+
getDomRef: getDomRef,
|
|
375
|
+
nodeType: nodeType,
|
|
423
376
|
offset: [0, 18],
|
|
424
|
-
absoluteOffset:
|
|
377
|
+
absoluteOffset: stickyScrollbar ? {
|
|
425
378
|
top: -6
|
|
426
379
|
} : {
|
|
427
380
|
top: 0
|
|
@@ -436,7 +389,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
|
|
|
436
389
|
items: [{
|
|
437
390
|
state: state,
|
|
438
391
|
formatMessage: intl.formatMessage,
|
|
439
|
-
nodeType:
|
|
392
|
+
nodeType: nodeType,
|
|
440
393
|
onMouseEnter: (0, _commands.hoverTable)(false, true),
|
|
441
394
|
onMouseLeave: (0, _commands.clearHoverSelection)(),
|
|
442
395
|
onFocus: (0, _commands.hoverTable)(false, true),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.FloatingToolbarLabel = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
10
|
+
var FloatingToolbarLabel = exports.FloatingToolbarLabel = /*#__PURE__*/_react.default.memo(function (props) {
|
|
11
|
+
var target = props.target,
|
|
12
|
+
content = props.content,
|
|
13
|
+
alignX = props.alignX,
|
|
14
|
+
alignY = props.alignY,
|
|
15
|
+
zIndex = props.zIndex,
|
|
16
|
+
forcePlacement = props.forcePlacement,
|
|
17
|
+
stick = props.stick,
|
|
18
|
+
offset = props.offset;
|
|
19
|
+
return /*#__PURE__*/_react.default.createElement(_ui.Popup, {
|
|
20
|
+
target: target,
|
|
21
|
+
alignX: alignX,
|
|
22
|
+
alignY: alignY,
|
|
23
|
+
zIndex: zIndex,
|
|
24
|
+
stick: stick,
|
|
25
|
+
forcePlacement: forcePlacement,
|
|
26
|
+
offset: offset
|
|
27
|
+
}, content);
|
|
28
|
+
});
|
|
@@ -9,17 +9,30 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
var _reactIntlNext = require("react-intl-next");
|
|
10
10
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
11
|
var _primitives = require("@atlaskit/primitives");
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
height: "var(--ds-space-300, 24px)",
|
|
12
|
+
var tableFullWidthLabelWrapperStyles = (0, _primitives.xcss)({
|
|
13
|
+
height: "var(--ds-space-400, 32px)",
|
|
15
14
|
display: 'flex',
|
|
16
|
-
|
|
15
|
+
backgroundColor: 'elevation.surface.overlay',
|
|
16
|
+
borderRadius: 'border.radius',
|
|
17
|
+
boxShadow: 'elevation.shadow.overlay',
|
|
18
|
+
lineHeight: 1,
|
|
19
|
+
boxSizing: 'border-box',
|
|
17
20
|
alignItems: 'center'
|
|
18
21
|
});
|
|
22
|
+
var tableFullWidthLabelStyles = (0, _primitives.xcss)({
|
|
23
|
+
marginLeft: 'space.100',
|
|
24
|
+
marginRight: 'space.100',
|
|
25
|
+
paddingLeft: 'space.075',
|
|
26
|
+
paddingRight: 'space.075',
|
|
27
|
+
paddingTop: 'space.050',
|
|
28
|
+
paddingBottom: 'space.050'
|
|
29
|
+
});
|
|
19
30
|
var FullWidthDisplay = exports.FullWidthDisplay = function FullWidthDisplay() {
|
|
20
31
|
var _useIntl = (0, _reactIntlNext.useIntl)(),
|
|
21
32
|
formatMessage = _useIntl.formatMessage;
|
|
22
33
|
return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
|
|
34
|
+
xcss: tableFullWidthLabelWrapperStyles
|
|
35
|
+
}, /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
|
|
23
36
|
xcss: tableFullWidthLabelStyles
|
|
24
|
-
},
|
|
37
|
+
}, formatMessage(_messages.tableMessages.fullWidthLabel)));
|
|
25
38
|
};
|
|
@@ -140,7 +140,9 @@ export const TableResizer = ({
|
|
|
140
140
|
displayGapCursor(true);
|
|
141
141
|
displayGuideline([]);
|
|
142
142
|
tr.setMeta(tableWidthPluginKey, {
|
|
143
|
-
resizing: false
|
|
143
|
+
resizing: false,
|
|
144
|
+
tableLocalId: '',
|
|
145
|
+
tableRef: null
|
|
144
146
|
});
|
|
145
147
|
dispatch(tr);
|
|
146
148
|
}
|
|
@@ -157,7 +159,9 @@ export const TableResizer = ({
|
|
|
157
159
|
} = editorView;
|
|
158
160
|
displayGapCursor(false);
|
|
159
161
|
tr.setMeta(tableWidthPluginKey, {
|
|
160
|
-
resizing: true
|
|
162
|
+
resizing: true,
|
|
163
|
+
tableLocalId: node.attrs.localId,
|
|
164
|
+
tableRef: tableRef
|
|
161
165
|
});
|
|
162
166
|
tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
163
167
|
name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
|
|
@@ -168,7 +172,7 @@ export const TableResizer = ({
|
|
|
168
172
|
if (onResizeStart) {
|
|
169
173
|
onResizeStart();
|
|
170
174
|
}
|
|
171
|
-
}, [startMeasure, editorView, displayGapCursor, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
175
|
+
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
172
176
|
const handleResize = useCallback((originalState, delta) => {
|
|
173
177
|
var _node$attrs$localId, _node$attrs;
|
|
174
178
|
countFrames();
|
|
@@ -219,7 +223,9 @@ export const TableResizer = ({
|
|
|
219
223
|
const currentTableNodeLocalId = (_node$attrs$localId2 = node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.localId) !== null && _node$attrs$localId2 !== void 0 ? _node$attrs$localId2 : '';
|
|
220
224
|
newWidth = widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId] ? TABLE_MAX_WIDTH : newWidth;
|
|
221
225
|
let tr = state.tr.setMeta(tableWidthPluginKey, {
|
|
222
|
-
resizing: false
|
|
226
|
+
resizing: false,
|
|
227
|
+
tableLocalId: '',
|
|
228
|
+
tableRef: null
|
|
223
229
|
});
|
|
224
230
|
const frameRateSamples = endMeasure();
|
|
225
231
|
if (frameRateSamples.length > 0) {
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -8,6 +8,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
|
|
|
8
8
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
9
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
10
10
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
11
|
+
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
11
12
|
import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
12
13
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
13
14
|
import { insertTableWithSize } from './commands/insert';
|
|
@@ -34,6 +35,8 @@ import FloatingContextualMenu from './ui/FloatingContextualMenu';
|
|
|
34
35
|
import FloatingDeleteButton from './ui/FloatingDeleteButton';
|
|
35
36
|
import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
36
37
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
38
|
+
import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
|
|
39
|
+
import { FullWidthDisplay } from './ui/TableFullWidthLabel';
|
|
37
40
|
import { createTableWithWidth } from './utils';
|
|
38
41
|
const defaultGetEditorFeatureFlags = () => ({});
|
|
39
42
|
|
|
@@ -312,7 +315,10 @@ const tablesPlugin = ({
|
|
|
312
315
|
}) => {
|
|
313
316
|
const isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
314
317
|
const isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
318
|
+
const resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
|
|
319
|
+
const resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
|
|
315
320
|
const isResizing = isColumnResizing || isTableResizing;
|
|
321
|
+
const widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
|
|
316
322
|
const {
|
|
317
323
|
tableNode,
|
|
318
324
|
tablePos,
|
|
@@ -393,6 +399,15 @@ const tablesPlugin = ({
|
|
|
393
399
|
stickyHeaders: stickyHeader,
|
|
394
400
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
395
401
|
editorAnalyticsAPI: editorAnalyticsAPI
|
|
402
|
+
}), (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/React.createElement(FloatingToolbarLabel, {
|
|
403
|
+
target: resizingTableRef,
|
|
404
|
+
content: /*#__PURE__*/React.createElement(FullWidthDisplay, null),
|
|
405
|
+
alignX: 'center',
|
|
406
|
+
alignY: 'bottom',
|
|
407
|
+
stick: true,
|
|
408
|
+
forcePlacement: true,
|
|
409
|
+
zIndex: akEditorFloatingPanelZIndex,
|
|
410
|
+
offset: [0, 10]
|
|
396
411
|
}));
|
|
397
412
|
}
|
|
398
413
|
}));
|
|
@@ -19,17 +19,26 @@ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTabl
|
|
|
19
19
|
state: {
|
|
20
20
|
init() {
|
|
21
21
|
return {
|
|
22
|
-
resizing: false
|
|
22
|
+
resizing: false,
|
|
23
|
+
tableLocalId: '',
|
|
24
|
+
tableRef: null
|
|
23
25
|
};
|
|
24
26
|
},
|
|
25
27
|
apply(tr, pluginState) {
|
|
26
28
|
const meta = tr.getMeta(pluginKey);
|
|
27
|
-
if (meta
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (meta) {
|
|
30
|
+
const keys = Object.keys(meta);
|
|
31
|
+
const changed = keys.some(key => {
|
|
32
|
+
return pluginState[key] !== meta[key];
|
|
33
|
+
});
|
|
34
|
+
if (changed) {
|
|
35
|
+
const newState = {
|
|
36
|
+
...pluginState,
|
|
37
|
+
...meta
|
|
38
|
+
};
|
|
39
|
+
dispatch(pluginKey, newState);
|
|
40
|
+
return newState;
|
|
41
|
+
}
|
|
33
42
|
}
|
|
34
43
|
return pluginState;
|
|
35
44
|
}
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -25,7 +25,6 @@ import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
|
25
25
|
import { canMergeCells } from './transforms';
|
|
26
26
|
import { TableCssClassName } from './types';
|
|
27
27
|
import { DisplayModeIcon } from './ui/icons';
|
|
28
|
-
import { FullWidthDisplay } from './ui/TableFullWidthLabel';
|
|
29
28
|
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, isTableNested } from './utils';
|
|
30
29
|
export const getToolbarMenuConfig = (config, state, {
|
|
31
30
|
formatMessage
|
|
@@ -302,7 +301,6 @@ export const getClosestSelectionOrTableRect = state => {
|
|
|
302
301
|
return isSelectionType(selection, 'cell') ? getSelectionRect(selection) : tableRect;
|
|
303
302
|
};
|
|
304
303
|
export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, getEditorView, options) => config => (state, intl) => {
|
|
305
|
-
var _tableObject$node$att, _tableObject$node, _tableObject$node$att2;
|
|
306
304
|
const tableObject = findTable(state.selection);
|
|
307
305
|
const pluginState = getPluginState(state);
|
|
308
306
|
const resizeState = tableResizingPluginKey.getState(state);
|
|
@@ -310,54 +308,6 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
|
|
|
310
308
|
|
|
311
309
|
// We don't want to show floating toolbar while resizing the table
|
|
312
310
|
const isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
313
|
-
const {
|
|
314
|
-
widthToWidest
|
|
315
|
-
} = pluginState;
|
|
316
|
-
const currentTableNodeLocalId = (_tableObject$node$att = tableObject === null || tableObject === void 0 ? void 0 : (_tableObject$node = tableObject.node) === null || _tableObject$node === void 0 ? void 0 : (_tableObject$node$att2 = _tableObject$node.attrs) === null || _tableObject$node$att2 === void 0 ? void 0 : _tableObject$node$att2.localId) !== null && _tableObject$node$att !== void 0 ? _tableObject$node$att : '';
|
|
317
|
-
if (options !== null && options !== void 0 && options.isTableScalingEnabled && isWidthResizing && widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId]) {
|
|
318
|
-
const {
|
|
319
|
-
stickyScrollbar
|
|
320
|
-
} = getEditorFeatureFlags();
|
|
321
|
-
const nodeType = state.schema.nodes.table;
|
|
322
|
-
const getDomRef = editorView => {
|
|
323
|
-
let element;
|
|
324
|
-
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
325
|
-
const parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
|
|
326
|
-
if (parent) {
|
|
327
|
-
const tableRef = parent.querySelector('table') || undefined;
|
|
328
|
-
if (tableRef) {
|
|
329
|
-
element = closestElement(tableRef, `.${TableCssClassName.TABLE_NODE_WRAPPER}`) || undefined;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return element;
|
|
333
|
-
};
|
|
334
|
-
const fullWidthLabel = {
|
|
335
|
-
id: 'editor.table.fullWidthLabel',
|
|
336
|
-
type: 'custom',
|
|
337
|
-
fallback: [],
|
|
338
|
-
render: () => {
|
|
339
|
-
return jsx(FullWidthDisplay, {
|
|
340
|
-
key: 'full-width-label'
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
return {
|
|
345
|
-
title: 'Table floating label',
|
|
346
|
-
getDomRef,
|
|
347
|
-
nodeType,
|
|
348
|
-
key: 'full-width-label',
|
|
349
|
-
offset: [0, 18],
|
|
350
|
-
absoluteOffset: stickyScrollbar ? {
|
|
351
|
-
top: -6
|
|
352
|
-
} : {
|
|
353
|
-
top: 0
|
|
354
|
-
},
|
|
355
|
-
zIndex: akEditorFloatingPanelZIndex + 1,
|
|
356
|
-
// Place the context menu slightly above the others
|
|
357
|
-
items: [fullWidthLabel],
|
|
358
|
-
scrollable: true
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
311
|
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
362
312
|
const nodeType = state.schema.nodes.table;
|
|
363
313
|
const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
3
|
+
export const FloatingToolbarLabel = /*#__PURE__*/React.memo(props => {
|
|
4
|
+
const {
|
|
5
|
+
target,
|
|
6
|
+
content,
|
|
7
|
+
alignX,
|
|
8
|
+
alignY,
|
|
9
|
+
zIndex,
|
|
10
|
+
forcePlacement,
|
|
11
|
+
stick,
|
|
12
|
+
offset
|
|
13
|
+
} = props;
|
|
14
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
15
|
+
target: target,
|
|
16
|
+
alignX: alignX,
|
|
17
|
+
alignY: alignY,
|
|
18
|
+
zIndex: zIndex,
|
|
19
|
+
stick: stick,
|
|
20
|
+
forcePlacement: forcePlacement,
|
|
21
|
+
offset: offset
|
|
22
|
+
}, content);
|
|
23
|
+
});
|
|
@@ -2,18 +2,31 @@ import React from 'react';
|
|
|
2
2
|
import { useIntl } from 'react-intl-next';
|
|
3
3
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
4
4
|
import { Box, Inline, xcss } from '@atlaskit/primitives';
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
height: "var(--ds-space-300, 24px)",
|
|
5
|
+
const tableFullWidthLabelWrapperStyles = xcss({
|
|
6
|
+
height: "var(--ds-space-400, 32px)",
|
|
8
7
|
display: 'flex',
|
|
9
|
-
|
|
8
|
+
backgroundColor: 'elevation.surface.overlay',
|
|
9
|
+
borderRadius: 'border.radius',
|
|
10
|
+
boxShadow: 'elevation.shadow.overlay',
|
|
11
|
+
lineHeight: 1,
|
|
12
|
+
boxSizing: 'border-box',
|
|
10
13
|
alignItems: 'center'
|
|
11
14
|
});
|
|
15
|
+
const tableFullWidthLabelStyles = xcss({
|
|
16
|
+
marginLeft: 'space.100',
|
|
17
|
+
marginRight: 'space.100',
|
|
18
|
+
paddingLeft: 'space.075',
|
|
19
|
+
paddingRight: 'space.075',
|
|
20
|
+
paddingTop: 'space.050',
|
|
21
|
+
paddingBottom: 'space.050'
|
|
22
|
+
});
|
|
12
23
|
export const FullWidthDisplay = () => {
|
|
13
24
|
const {
|
|
14
25
|
formatMessage
|
|
15
26
|
} = useIntl();
|
|
16
27
|
return /*#__PURE__*/React.createElement(Box, {
|
|
28
|
+
xcss: tableFullWidthLabelWrapperStyles
|
|
29
|
+
}, /*#__PURE__*/React.createElement(Inline, {
|
|
17
30
|
xcss: tableFullWidthLabelStyles
|
|
18
|
-
},
|
|
31
|
+
}, formatMessage(messages.fullWidthLabel)));
|
|
19
32
|
};
|
|
@@ -139,7 +139,9 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
139
139
|
displayGapCursor(true);
|
|
140
140
|
displayGuideline([]);
|
|
141
141
|
_tr.setMeta(tableWidthPluginKey, {
|
|
142
|
-
resizing: false
|
|
142
|
+
resizing: false,
|
|
143
|
+
tableLocalId: '',
|
|
144
|
+
tableRef: null
|
|
143
145
|
});
|
|
144
146
|
dispatch(_tr);
|
|
145
147
|
}
|
|
@@ -152,7 +154,9 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
152
154
|
tr = editorView.state.tr;
|
|
153
155
|
displayGapCursor(false);
|
|
154
156
|
tr.setMeta(tableWidthPluginKey, {
|
|
155
|
-
resizing: true
|
|
157
|
+
resizing: true,
|
|
158
|
+
tableLocalId: node.attrs.localId,
|
|
159
|
+
tableRef: tableRef
|
|
156
160
|
});
|
|
157
161
|
tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
158
162
|
name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
|
|
@@ -163,7 +167,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
163
167
|
if (onResizeStart) {
|
|
164
168
|
onResizeStart();
|
|
165
169
|
}
|
|
166
|
-
}, [startMeasure, editorView, displayGapCursor, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
170
|
+
}, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
|
|
167
171
|
var handleResize = useCallback(function (originalState, delta) {
|
|
168
172
|
var _node$attrs$localId, _node$attrs;
|
|
169
173
|
countFrames();
|
|
@@ -212,7 +216,9 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
212
216
|
var currentTableNodeLocalId = (_node$attrs$localId2 = node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.localId) !== null && _node$attrs$localId2 !== void 0 ? _node$attrs$localId2 : '';
|
|
213
217
|
newWidth = widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId] ? TABLE_MAX_WIDTH : newWidth;
|
|
214
218
|
var tr = state.tr.setMeta(tableWidthPluginKey, {
|
|
215
|
-
resizing: false
|
|
219
|
+
resizing: false,
|
|
220
|
+
tableLocalId: '',
|
|
221
|
+
tableRef: null
|
|
216
222
|
});
|
|
217
223
|
var frameRateSamples = endMeasure();
|
|
218
224
|
if (frameRateSamples.length > 0) {
|
package/dist/esm/plugin.js
CHANGED
|
@@ -8,6 +8,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
|
|
|
8
8
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
9
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
10
10
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
11
|
+
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
11
12
|
import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
12
13
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
13
14
|
import { insertTableWithSize } from './commands/insert';
|
|
@@ -34,6 +35,8 @@ import FloatingContextualMenu from './ui/FloatingContextualMenu';
|
|
|
34
35
|
import FloatingDeleteButton from './ui/FloatingDeleteButton';
|
|
35
36
|
import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
36
37
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
38
|
+
import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
|
|
39
|
+
import { FullWidthDisplay } from './ui/TableFullWidthLabel';
|
|
37
40
|
import { createTableWithWidth } from './utils';
|
|
38
41
|
var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
|
|
39
42
|
return {};
|
|
@@ -312,7 +315,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
312
315
|
dragAndDropState = _ref17.dragAndDropState;
|
|
313
316
|
var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
314
317
|
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
318
|
+
var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
|
|
319
|
+
var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
|
|
315
320
|
var isResizing = isColumnResizing || isTableResizing;
|
|
321
|
+
var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
|
|
316
322
|
var _ref18 = tablePluginState,
|
|
317
323
|
tableNode = _ref18.tableNode,
|
|
318
324
|
tablePos = _ref18.tablePos,
|
|
@@ -390,6 +396,15 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
390
396
|
stickyHeaders: stickyHeader,
|
|
391
397
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
392
398
|
editorAnalyticsAPI: editorAnalyticsAPI
|
|
399
|
+
}), (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/React.createElement(FloatingToolbarLabel, {
|
|
400
|
+
target: resizingTableRef,
|
|
401
|
+
content: /*#__PURE__*/React.createElement(FullWidthDisplay, null),
|
|
402
|
+
alignX: 'center',
|
|
403
|
+
alignY: 'bottom',
|
|
404
|
+
stick: true,
|
|
405
|
+
forcePlacement: true,
|
|
406
|
+
zIndex: akEditorFloatingPanelZIndex,
|
|
407
|
+
offset: [0, 10]
|
|
393
408
|
}));
|
|
394
409
|
}
|
|
395
410
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
var _excluded = ["width"];
|
|
4
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -24,17 +24,23 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
|
|
|
24
24
|
state: {
|
|
25
25
|
init: function init() {
|
|
26
26
|
return {
|
|
27
|
-
resizing: false
|
|
27
|
+
resizing: false,
|
|
28
|
+
tableLocalId: '',
|
|
29
|
+
tableRef: null
|
|
28
30
|
};
|
|
29
31
|
},
|
|
30
32
|
apply: function apply(tr, pluginState) {
|
|
31
33
|
var meta = tr.getMeta(pluginKey);
|
|
32
|
-
if (meta
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
if (meta) {
|
|
35
|
+
var keys = Object.keys(meta);
|
|
36
|
+
var changed = keys.some(function (key) {
|
|
37
|
+
return pluginState[key] !== meta[key];
|
|
38
|
+
});
|
|
39
|
+
if (changed) {
|
|
40
|
+
var newState = _objectSpread(_objectSpread({}, pluginState), meta);
|
|
41
|
+
dispatch(pluginKey, newState);
|
|
42
|
+
return newState;
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
return pluginState;
|
|
40
46
|
}
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -26,7 +26,6 @@ import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
|
26
26
|
import { canMergeCells } from './transforms';
|
|
27
27
|
import { TableCssClassName } from './types';
|
|
28
28
|
import { DisplayModeIcon } from './ui/icons';
|
|
29
|
-
import { FullWidthDisplay } from './ui/TableFullWidthLabel';
|
|
30
29
|
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, isTableNested } from './utils';
|
|
31
30
|
export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
|
|
32
31
|
var formatMessage = _ref.formatMessage;
|
|
@@ -305,7 +304,6 @@ export var getClosestSelectionOrTableRect = function getClosestSelectionOrTableR
|
|
|
305
304
|
export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, getEditorView, options) {
|
|
306
305
|
return function (config) {
|
|
307
306
|
return function (state, intl) {
|
|
308
|
-
var _tableObject$node$att, _tableObject$node;
|
|
309
307
|
var tableObject = findTable(state.selection);
|
|
310
308
|
var pluginState = getPluginState(state);
|
|
311
309
|
var resizeState = tableResizingPluginKey.getState(state);
|
|
@@ -313,53 +311,8 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
313
311
|
|
|
314
312
|
// We don't want to show floating toolbar while resizing the table
|
|
315
313
|
var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
316
|
-
var widthToWidest = pluginState.widthToWidest;
|
|
317
|
-
var currentTableNodeLocalId = (_tableObject$node$att = tableObject === null || tableObject === void 0 || (_tableObject$node = tableObject.node) === null || _tableObject$node === void 0 || (_tableObject$node = _tableObject$node.attrs) === null || _tableObject$node === void 0 ? void 0 : _tableObject$node.localId) !== null && _tableObject$node$att !== void 0 ? _tableObject$node$att : '';
|
|
318
|
-
if (options !== null && options !== void 0 && options.isTableScalingEnabled && isWidthResizing && widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId]) {
|
|
319
|
-
var _getEditorFeatureFlag = getEditorFeatureFlags(),
|
|
320
|
-
stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
|
|
321
|
-
var nodeType = state.schema.nodes.table;
|
|
322
|
-
var getDomRef = function getDomRef(editorView) {
|
|
323
|
-
var element;
|
|
324
|
-
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
325
|
-
var parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
|
|
326
|
-
if (parent) {
|
|
327
|
-
var tableRef = parent.querySelector('table') || undefined;
|
|
328
|
-
if (tableRef) {
|
|
329
|
-
element = closestElement(tableRef, ".".concat(TableCssClassName.TABLE_NODE_WRAPPER)) || undefined;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return element;
|
|
333
|
-
};
|
|
334
|
-
var fullWidthLabel = {
|
|
335
|
-
id: 'editor.table.fullWidthLabel',
|
|
336
|
-
type: 'custom',
|
|
337
|
-
fallback: [],
|
|
338
|
-
render: function render() {
|
|
339
|
-
return jsx(FullWidthDisplay, {
|
|
340
|
-
key: 'full-width-label'
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
return {
|
|
345
|
-
title: 'Table floating label',
|
|
346
|
-
getDomRef: getDomRef,
|
|
347
|
-
nodeType: nodeType,
|
|
348
|
-
key: 'full-width-label',
|
|
349
|
-
offset: [0, 18],
|
|
350
|
-
absoluteOffset: stickyScrollbar ? {
|
|
351
|
-
top: -6
|
|
352
|
-
} : {
|
|
353
|
-
top: 0
|
|
354
|
-
},
|
|
355
|
-
zIndex: akEditorFloatingPanelZIndex + 1,
|
|
356
|
-
// Place the context menu slightly above the others
|
|
357
|
-
items: [fullWidthLabel],
|
|
358
|
-
scrollable: true
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
314
|
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
362
|
-
var
|
|
315
|
+
var nodeType = state.schema.nodes.table;
|
|
363
316
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
364
317
|
var cellItems;
|
|
365
318
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
@@ -391,10 +344,10 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
391
344
|
};
|
|
392
345
|
};
|
|
393
346
|
}
|
|
394
|
-
var
|
|
347
|
+
var getDomRef = function getDomRef(editorView) {
|
|
395
348
|
var element;
|
|
396
349
|
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
397
|
-
var parent = findParentDomRefOfType(
|
|
350
|
+
var parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
|
|
398
351
|
if (parent) {
|
|
399
352
|
var tableRef = parent.querySelector('table') || undefined;
|
|
400
353
|
if (tableRef) {
|
|
@@ -403,14 +356,14 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
403
356
|
}
|
|
404
357
|
return element;
|
|
405
358
|
};
|
|
406
|
-
var
|
|
407
|
-
|
|
359
|
+
var _getEditorFeatureFlag = getEditorFeatureFlags(),
|
|
360
|
+
stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
|
|
408
361
|
return {
|
|
409
362
|
title: 'Table floating controls',
|
|
410
|
-
getDomRef:
|
|
411
|
-
nodeType:
|
|
363
|
+
getDomRef: getDomRef,
|
|
364
|
+
nodeType: nodeType,
|
|
412
365
|
offset: [0, 18],
|
|
413
|
-
absoluteOffset:
|
|
366
|
+
absoluteOffset: stickyScrollbar ? {
|
|
414
367
|
top: -6
|
|
415
368
|
} : {
|
|
416
369
|
top: 0
|
|
@@ -425,7 +378,7 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
425
378
|
items: [{
|
|
426
379
|
state: state,
|
|
427
380
|
formatMessage: intl.formatMessage,
|
|
428
|
-
nodeType:
|
|
381
|
+
nodeType: nodeType,
|
|
429
382
|
onMouseEnter: hoverTable(false, true),
|
|
430
383
|
onMouseLeave: clearHoverSelection(),
|
|
431
384
|
onFocus: hoverTable(false, true),
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
3
|
+
export var FloatingToolbarLabel = /*#__PURE__*/React.memo(function (props) {
|
|
4
|
+
var target = props.target,
|
|
5
|
+
content = props.content,
|
|
6
|
+
alignX = props.alignX,
|
|
7
|
+
alignY = props.alignY,
|
|
8
|
+
zIndex = props.zIndex,
|
|
9
|
+
forcePlacement = props.forcePlacement,
|
|
10
|
+
stick = props.stick,
|
|
11
|
+
offset = props.offset;
|
|
12
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
13
|
+
target: target,
|
|
14
|
+
alignX: alignX,
|
|
15
|
+
alignY: alignY,
|
|
16
|
+
zIndex: zIndex,
|
|
17
|
+
stick: stick,
|
|
18
|
+
forcePlacement: forcePlacement,
|
|
19
|
+
offset: offset
|
|
20
|
+
}, content);
|
|
21
|
+
});
|
|
@@ -2,17 +2,30 @@ import React from 'react';
|
|
|
2
2
|
import { useIntl } from 'react-intl-next';
|
|
3
3
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
4
4
|
import { Box, Inline, xcss } from '@atlaskit/primitives';
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
height: "var(--ds-space-300, 24px)",
|
|
5
|
+
var tableFullWidthLabelWrapperStyles = xcss({
|
|
6
|
+
height: "var(--ds-space-400, 32px)",
|
|
8
7
|
display: 'flex',
|
|
9
|
-
|
|
8
|
+
backgroundColor: 'elevation.surface.overlay',
|
|
9
|
+
borderRadius: 'border.radius',
|
|
10
|
+
boxShadow: 'elevation.shadow.overlay',
|
|
11
|
+
lineHeight: 1,
|
|
12
|
+
boxSizing: 'border-box',
|
|
10
13
|
alignItems: 'center'
|
|
11
14
|
});
|
|
15
|
+
var tableFullWidthLabelStyles = xcss({
|
|
16
|
+
marginLeft: 'space.100',
|
|
17
|
+
marginRight: 'space.100',
|
|
18
|
+
paddingLeft: 'space.075',
|
|
19
|
+
paddingRight: 'space.075',
|
|
20
|
+
paddingTop: 'space.050',
|
|
21
|
+
paddingBottom: 'space.050'
|
|
22
|
+
});
|
|
12
23
|
export var FullWidthDisplay = function FullWidthDisplay() {
|
|
13
24
|
var _useIntl = useIntl(),
|
|
14
25
|
formatMessage = _useIntl.formatMessage;
|
|
15
26
|
return /*#__PURE__*/React.createElement(Box, {
|
|
27
|
+
xcss: tableFullWidthLabelWrapperStyles
|
|
28
|
+
}, /*#__PURE__*/React.createElement(Inline, {
|
|
16
29
|
xcss: tableFullWidthLabelStyles
|
|
17
|
-
},
|
|
30
|
+
}, formatMessage(messages.fullWidthLabel)));
|
|
18
31
|
};
|
|
@@ -9,9 +9,13 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
9
9
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
10
10
|
type TableWidthPluginState = {
|
|
11
11
|
resizing: boolean;
|
|
12
|
+
tableLocalId: string;
|
|
13
|
+
tableRef: HTMLTableElement | null;
|
|
12
14
|
};
|
|
13
15
|
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
14
16
|
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean) => SafePlugin<{
|
|
15
17
|
resizing: boolean;
|
|
18
|
+
tableLocalId: string;
|
|
19
|
+
tableRef: null;
|
|
16
20
|
}>;
|
|
17
21
|
export { createPlugin };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface Props {
|
|
3
|
+
target: HTMLElement;
|
|
4
|
+
content: React.ReactNode;
|
|
5
|
+
alignX?: 'left' | 'center' | 'right';
|
|
6
|
+
alignY?: "top" | "bottom" | "start";
|
|
7
|
+
zIndex?: number;
|
|
8
|
+
forcePlacement?: boolean;
|
|
9
|
+
stick?: boolean;
|
|
10
|
+
offset?: [number, number];
|
|
11
|
+
}
|
|
12
|
+
export declare const FloatingToolbarLabel: React.MemoExoticComponent<(props: Props) => JSX.Element>;
|
|
@@ -9,9 +9,13 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
9
9
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
10
10
|
type TableWidthPluginState = {
|
|
11
11
|
resizing: boolean;
|
|
12
|
+
tableLocalId: string;
|
|
13
|
+
tableRef: HTMLTableElement | null;
|
|
12
14
|
};
|
|
13
15
|
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
14
16
|
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean) => SafePlugin<{
|
|
15
17
|
resizing: boolean;
|
|
18
|
+
tableLocalId: string;
|
|
19
|
+
tableRef: null;
|
|
16
20
|
}>;
|
|
17
21
|
export { createPlugin };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface Props {
|
|
3
|
+
target: HTMLElement;
|
|
4
|
+
content: React.ReactNode;
|
|
5
|
+
alignX?: 'left' | 'center' | 'right';
|
|
6
|
+
alignY?: "top" | "bottom" | "start";
|
|
7
|
+
zIndex?: number;
|
|
8
|
+
forcePlacement?: boolean;
|
|
9
|
+
stick?: boolean;
|
|
10
|
+
offset?: [
|
|
11
|
+
number,
|
|
12
|
+
number
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
export declare const FloatingToolbarLabel: React.MemoExoticComponent<(props: Props) => JSX.Element>;
|
package/package.json
CHANGED
|
@@ -241,7 +241,11 @@ export const TableResizer = ({
|
|
|
241
241
|
} = editorView;
|
|
242
242
|
displayGapCursor(true);
|
|
243
243
|
displayGuideline([]);
|
|
244
|
-
tr.setMeta(tableWidthPluginKey, {
|
|
244
|
+
tr.setMeta(tableWidthPluginKey, {
|
|
245
|
+
resizing: false,
|
|
246
|
+
tableLocalId: '',
|
|
247
|
+
tableRef: null,
|
|
248
|
+
});
|
|
245
249
|
dispatch(tr);
|
|
246
250
|
}
|
|
247
251
|
};
|
|
@@ -255,7 +259,12 @@ export const TableResizer = ({
|
|
|
255
259
|
state: { tr },
|
|
256
260
|
} = editorView;
|
|
257
261
|
displayGapCursor(false);
|
|
258
|
-
|
|
262
|
+
|
|
263
|
+
tr.setMeta(tableWidthPluginKey, {
|
|
264
|
+
resizing: true,
|
|
265
|
+
tableLocalId: node.attrs.localId,
|
|
266
|
+
tableRef: tableRef,
|
|
267
|
+
});
|
|
259
268
|
tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
260
269
|
name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED,
|
|
261
270
|
});
|
|
@@ -277,6 +286,8 @@ export const TableResizer = ({
|
|
|
277
286
|
startMeasure,
|
|
278
287
|
editorView,
|
|
279
288
|
displayGapCursor,
|
|
289
|
+
node.attrs.localId,
|
|
290
|
+
tableRef,
|
|
280
291
|
isTableScalingEnabled,
|
|
281
292
|
containerWidth,
|
|
282
293
|
displayGuideline,
|
|
@@ -374,7 +385,11 @@ export const TableResizer = ({
|
|
|
374
385
|
? TABLE_MAX_WIDTH
|
|
375
386
|
: newWidth;
|
|
376
387
|
|
|
377
|
-
let tr = state.tr.setMeta(tableWidthPluginKey, {
|
|
388
|
+
let tr = state.tr.setMeta(tableWidthPluginKey, {
|
|
389
|
+
resizing: false,
|
|
390
|
+
tableLocalId: '',
|
|
391
|
+
tableRef: null,
|
|
392
|
+
});
|
|
378
393
|
const frameRateSamples = endMeasure();
|
|
379
394
|
|
|
380
395
|
if (frameRateSamples.length > 0) {
|
package/src/plugin.tsx
CHANGED
|
@@ -41,6 +41,7 @@ import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
|
41
41
|
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
42
42
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
43
43
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
44
|
+
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
44
45
|
import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
45
46
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
46
47
|
|
|
@@ -87,6 +88,8 @@ import FloatingContextualMenu from './ui/FloatingContextualMenu';
|
|
|
87
88
|
import FloatingDeleteButton from './ui/FloatingDeleteButton';
|
|
88
89
|
import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
89
90
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
91
|
+
import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
|
|
92
|
+
import { FullWidthDisplay } from './ui/TableFullWidthLabel';
|
|
90
93
|
import { createTableWithWidth } from './utils';
|
|
91
94
|
|
|
92
95
|
export interface TablePluginOptions {
|
|
@@ -480,7 +483,10 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
480
483
|
}) => {
|
|
481
484
|
const isColumnResizing = resizingPluginState?.dragging;
|
|
482
485
|
const isTableResizing = tableWidthPluginState?.resizing;
|
|
486
|
+
const resizingTableLocalId = tableWidthPluginState?.tableLocalId;
|
|
487
|
+
const resizingTableRef = tableWidthPluginState?.tableRef;
|
|
483
488
|
const isResizing = isColumnResizing || isTableResizing;
|
|
489
|
+
const widthToWidest = tablePluginState?.widthToWidest;
|
|
484
490
|
|
|
485
491
|
const {
|
|
486
492
|
tableNode,
|
|
@@ -593,6 +599,23 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
593
599
|
editorAnalyticsAPI={editorAnalyticsAPI}
|
|
594
600
|
/>
|
|
595
601
|
)}
|
|
602
|
+
{options?.isTableScalingEnabled &&
|
|
603
|
+
isTableResizing &&
|
|
604
|
+
widthToWidest &&
|
|
605
|
+
resizingTableLocalId &&
|
|
606
|
+
resizingTableRef &&
|
|
607
|
+
widthToWidest[resizingTableLocalId] && (
|
|
608
|
+
<FloatingToolbarLabel
|
|
609
|
+
target={resizingTableRef}
|
|
610
|
+
content={<FullWidthDisplay />}
|
|
611
|
+
alignX={'center'}
|
|
612
|
+
alignY={'bottom'}
|
|
613
|
+
stick={true}
|
|
614
|
+
forcePlacement={true}
|
|
615
|
+
zIndex={akEditorFloatingPanelZIndex}
|
|
616
|
+
offset={[0, 10]}
|
|
617
|
+
/>
|
|
618
|
+
)}
|
|
596
619
|
</>
|
|
597
620
|
);
|
|
598
621
|
}}
|
|
@@ -33,6 +33,8 @@ type __ReplaceStep = ReplaceStep & {
|
|
|
33
33
|
|
|
34
34
|
type TableWidthPluginState = {
|
|
35
35
|
resizing: boolean;
|
|
36
|
+
tableLocalId: string;
|
|
37
|
+
tableRef: HTMLTableElement | null;
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
export const pluginKey = new PluginKey<TableWidthPluginState>(
|
|
@@ -51,15 +53,24 @@ const createPlugin = (
|
|
|
51
53
|
init() {
|
|
52
54
|
return {
|
|
53
55
|
resizing: false,
|
|
56
|
+
tableLocalId: '',
|
|
57
|
+
tableRef: null,
|
|
54
58
|
};
|
|
55
59
|
},
|
|
56
60
|
apply(tr, pluginState) {
|
|
57
61
|
const meta = tr.getMeta(pluginKey);
|
|
58
|
-
if (meta
|
|
59
|
-
const
|
|
62
|
+
if (meta) {
|
|
63
|
+
const keys = Object.keys(meta) as Array<keyof TableWidthPluginState>;
|
|
64
|
+
const changed = keys.some((key) => {
|
|
65
|
+
return pluginState[key] !== meta[key];
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (changed) {
|
|
69
|
+
const newState = { ...pluginState, ...meta };
|
|
60
70
|
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
dispatch(pluginKey, newState);
|
|
72
|
+
return newState;
|
|
73
|
+
}
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
return pluginState;
|
package/src/toolbar.tsx
CHANGED
|
@@ -95,7 +95,6 @@ import type {
|
|
|
95
95
|
} from './types';
|
|
96
96
|
import { TableCssClassName } from './types';
|
|
97
97
|
import { DisplayModeIcon } from './ui/icons';
|
|
98
|
-
import { FullWidthDisplay } from './ui/TableFullWidthLabel';
|
|
99
98
|
import {
|
|
100
99
|
getMergedCellsPositions,
|
|
101
100
|
getSelectedColumnIndexes,
|
|
@@ -467,62 +466,6 @@ export const getToolbarConfig =
|
|
|
467
466
|
// We don't want to show floating toolbar while resizing the table
|
|
468
467
|
const isWidthResizing = tableWidthState?.resizing;
|
|
469
468
|
|
|
470
|
-
const { widthToWidest } = pluginState;
|
|
471
|
-
const currentTableNodeLocalId = tableObject?.node?.attrs?.localId ?? '';
|
|
472
|
-
|
|
473
|
-
if (
|
|
474
|
-
options?.isTableScalingEnabled &&
|
|
475
|
-
isWidthResizing &&
|
|
476
|
-
widthToWidest &&
|
|
477
|
-
currentTableNodeLocalId &&
|
|
478
|
-
widthToWidest[currentTableNodeLocalId]
|
|
479
|
-
) {
|
|
480
|
-
const { stickyScrollbar } = getEditorFeatureFlags();
|
|
481
|
-
|
|
482
|
-
const nodeType = state.schema.nodes.table;
|
|
483
|
-
const getDomRef = (editorView: EditorView) => {
|
|
484
|
-
let element: HTMLElement | undefined;
|
|
485
|
-
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
486
|
-
const parent = findParentDomRefOfType(
|
|
487
|
-
nodeType,
|
|
488
|
-
domAtPos,
|
|
489
|
-
)(state.selection);
|
|
490
|
-
if (parent) {
|
|
491
|
-
const tableRef =
|
|
492
|
-
(parent as HTMLElement).querySelector<HTMLTableElement>('table') ||
|
|
493
|
-
undefined;
|
|
494
|
-
if (tableRef) {
|
|
495
|
-
element =
|
|
496
|
-
closestElement(
|
|
497
|
-
tableRef,
|
|
498
|
-
`.${TableCssClassName.TABLE_NODE_WRAPPER}`,
|
|
499
|
-
) || undefined;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
return element;
|
|
503
|
-
};
|
|
504
|
-
const fullWidthLabel = {
|
|
505
|
-
id: 'editor.table.fullWidthLabel',
|
|
506
|
-
type: 'custom',
|
|
507
|
-
fallback: [],
|
|
508
|
-
render: () => {
|
|
509
|
-
return <FullWidthDisplay key={'full-width-label'} />;
|
|
510
|
-
},
|
|
511
|
-
} as FloatingToolbarItem<Command>;
|
|
512
|
-
|
|
513
|
-
return {
|
|
514
|
-
title: 'Table floating label',
|
|
515
|
-
getDomRef,
|
|
516
|
-
nodeType,
|
|
517
|
-
key: 'full-width-label',
|
|
518
|
-
offset: [0, 18],
|
|
519
|
-
absoluteOffset: stickyScrollbar ? { top: -6 } : { top: 0 },
|
|
520
|
-
zIndex: akEditorFloatingPanelZIndex + 1, // Place the context menu slightly above the others
|
|
521
|
-
items: [fullWidthLabel],
|
|
522
|
-
scrollable: true,
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
|
|
526
469
|
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
527
470
|
const nodeType = state.schema.nodes.table;
|
|
528
471
|
const menu = getToolbarMenuConfig(
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export interface Props {
|
|
8
|
+
target: HTMLElement;
|
|
9
|
+
content: React.ReactNode;
|
|
10
|
+
alignX?: 'left' | 'center' | 'right';
|
|
11
|
+
alignY?: "top" | "bottom" | "start";
|
|
12
|
+
zIndex?: number;
|
|
13
|
+
forcePlacement?: boolean;
|
|
14
|
+
stick?: boolean;
|
|
15
|
+
offset?: [number, number];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export const FloatingToolbarLabel = React.memo(
|
|
20
|
+
(props: Props ) => {
|
|
21
|
+
const {target,content, alignX, alignY, zIndex, forcePlacement, stick, offset} = props;
|
|
22
|
+
return (
|
|
23
|
+
<Popup
|
|
24
|
+
target={target}
|
|
25
|
+
alignX={alignX}
|
|
26
|
+
alignY={alignY}
|
|
27
|
+
zIndex={zIndex}
|
|
28
|
+
stick={stick}
|
|
29
|
+
forcePlacement={forcePlacement}
|
|
30
|
+
offset={offset}
|
|
31
|
+
>
|
|
32
|
+
{content}
|
|
33
|
+
</Popup>
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
);
|
|
@@ -6,19 +6,31 @@ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
|
6
6
|
import { Box, Inline, xcss } from '@atlaskit/primitives';
|
|
7
7
|
import { token } from '@atlaskit/tokens';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
height: token('space.300', '24px'),
|
|
9
|
+
const tableFullWidthLabelWrapperStyles = xcss({
|
|
10
|
+
height: token('space.400', '32px'),
|
|
12
11
|
display: 'flex',
|
|
13
|
-
|
|
12
|
+
backgroundColor: 'elevation.surface.overlay',
|
|
13
|
+
borderRadius: 'border.radius',
|
|
14
|
+
boxShadow:'elevation.shadow.overlay',
|
|
15
|
+
lineHeight: 1,
|
|
16
|
+
boxSizing: 'border-box',
|
|
14
17
|
alignItems: 'center',
|
|
15
18
|
});
|
|
16
19
|
|
|
20
|
+
const tableFullWidthLabelStyles = xcss({
|
|
21
|
+
marginLeft: 'space.100',
|
|
22
|
+
marginRight: 'space.100',
|
|
23
|
+
paddingLeft: 'space.075',
|
|
24
|
+
paddingRight: 'space.075',
|
|
25
|
+
paddingTop: 'space.050',
|
|
26
|
+
paddingBottom: 'space.050',
|
|
27
|
+
});
|
|
28
|
+
|
|
17
29
|
export const FullWidthDisplay = () => {
|
|
18
30
|
const { formatMessage } = useIntl();
|
|
19
31
|
return (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
<Box xcss={tableFullWidthLabelWrapperStyles}>
|
|
33
|
+
<Inline xcss={tableFullWidthLabelStyles}>{formatMessage(messages.fullWidthLabel)}</Inline>
|
|
34
|
+
</Box>
|
|
23
35
|
);
|
|
24
36
|
};
|