@atlaskit/editor-plugin-table 7.12.1 → 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 +22 -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 +11 -57
- 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 +3 -52
- 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 +12 -58
- 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 +5 -5
- 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 +5 -57
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +36 -0
- package/src/ui/TableFullWidthLabel/index.tsx +19 -7
|
@@ -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,8 +26,7 @@ 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 {
|
|
30
|
-
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes } from './utils';
|
|
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;
|
|
33
32
|
var optionItem = getBooleanFF('platform.editor.a11y-table-floating-toolbar-dropdown-menu_zkb33') ? 'item-checkbox' : 'item';
|
|
@@ -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),
|
|
@@ -503,7 +456,8 @@ var getColumnSettingItems = function getColumnSettingItems(editorState, editorVi
|
|
|
503
456
|
var newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, isTableScalingEnabled);
|
|
504
457
|
var wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
|
|
505
458
|
var items = [];
|
|
506
|
-
var
|
|
459
|
+
var isNested = pluginState.tablePos && isTableNested(editorState, pluginState.tablePos);
|
|
460
|
+
var isTableScalingLockBtnEnabled = !isNested && isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
|
|
507
461
|
if (isTableScalingLockBtnEnabled) {
|
|
508
462
|
var _pluginState$tableNod;
|
|
509
463
|
var areColumnWidthsLocked = (pluginState === null || pluginState === void 0 || (_pluginState$tableNod = pluginState.tableNode) === null || _pluginState$tableNod === void 0 ? void 0 : _pluginState$tableNod.attrs.displayMode) === 'fixed';
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.12.
|
|
3
|
+
"version": "7.12.3",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^35.12.2",
|
|
32
32
|
"@atlaskit/custom-steps": "^0.1.0",
|
|
33
|
-
"@atlaskit/editor-common": "^79.
|
|
33
|
+
"@atlaskit/editor-common": "^79.1.0",
|
|
34
34
|
"@atlaskit/editor-palette": "1.6.0",
|
|
35
35
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
|
|
36
36
|
"@atlaskit/editor-plugin-analytics": "^1.1.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@atlaskit/editor-plugin-guideline": "^1.1.0",
|
|
40
40
|
"@atlaskit/editor-plugin-selection": "^1.2.0",
|
|
41
41
|
"@atlaskit/editor-plugin-width": "^1.1.0",
|
|
42
|
-
"@atlaskit/editor-prosemirror": "4.0.
|
|
42
|
+
"@atlaskit/editor-prosemirror": "4.0.1",
|
|
43
43
|
"@atlaskit/editor-shared-styles": "^2.10.0",
|
|
44
44
|
"@atlaskit/editor-tables": "^2.7.0",
|
|
45
45
|
"@atlaskit/icon": "^22.1.0",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
|
|
49
49
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.3.0",
|
|
50
50
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
|
|
51
|
-
"@atlaskit/primitives": "^6.
|
|
51
|
+
"@atlaskit/primitives": "^6.1.0",
|
|
52
52
|
"@atlaskit/theme": "^12.7.0",
|
|
53
|
-
"@atlaskit/toggle": "^13.
|
|
53
|
+
"@atlaskit/toggle": "^13.1.0",
|
|
54
54
|
"@atlaskit/tokens": "^1.45.0",
|
|
55
55
|
"@atlaskit/tooltip": "^18.3.0",
|
|
56
56
|
"@babel/runtime": "^7.0.0",
|
|
@@ -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,11 +95,11 @@ 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,
|
|
102
101
|
getSelectedRowIndexes,
|
|
102
|
+
isTableNested,
|
|
103
103
|
} from './utils';
|
|
104
104
|
|
|
105
105
|
export const getToolbarMenuConfig = (
|
|
@@ -466,62 +466,6 @@ export const getToolbarConfig =
|
|
|
466
466
|
// We don't want to show floating toolbar while resizing the table
|
|
467
467
|
const isWidthResizing = tableWidthState?.resizing;
|
|
468
468
|
|
|
469
|
-
const { widthToWidest } = pluginState;
|
|
470
|
-
const currentTableNodeLocalId = tableObject?.node?.attrs?.localId ?? '';
|
|
471
|
-
|
|
472
|
-
if (
|
|
473
|
-
options?.isTableScalingEnabled &&
|
|
474
|
-
isWidthResizing &&
|
|
475
|
-
widthToWidest &&
|
|
476
|
-
currentTableNodeLocalId &&
|
|
477
|
-
widthToWidest[currentTableNodeLocalId]
|
|
478
|
-
) {
|
|
479
|
-
const { stickyScrollbar } = getEditorFeatureFlags();
|
|
480
|
-
|
|
481
|
-
const nodeType = state.schema.nodes.table;
|
|
482
|
-
const getDomRef = (editorView: EditorView) => {
|
|
483
|
-
let element: HTMLElement | undefined;
|
|
484
|
-
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
485
|
-
const parent = findParentDomRefOfType(
|
|
486
|
-
nodeType,
|
|
487
|
-
domAtPos,
|
|
488
|
-
)(state.selection);
|
|
489
|
-
if (parent) {
|
|
490
|
-
const tableRef =
|
|
491
|
-
(parent as HTMLElement).querySelector<HTMLTableElement>('table') ||
|
|
492
|
-
undefined;
|
|
493
|
-
if (tableRef) {
|
|
494
|
-
element =
|
|
495
|
-
closestElement(
|
|
496
|
-
tableRef,
|
|
497
|
-
`.${TableCssClassName.TABLE_NODE_WRAPPER}`,
|
|
498
|
-
) || undefined;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return element;
|
|
502
|
-
};
|
|
503
|
-
const fullWidthLabel = {
|
|
504
|
-
id: 'editor.table.fullWidthLabel',
|
|
505
|
-
type: 'custom',
|
|
506
|
-
fallback: [],
|
|
507
|
-
render: () => {
|
|
508
|
-
return <FullWidthDisplay key={'full-width-label'} />;
|
|
509
|
-
},
|
|
510
|
-
} as FloatingToolbarItem<Command>;
|
|
511
|
-
|
|
512
|
-
return {
|
|
513
|
-
title: 'Table floating label',
|
|
514
|
-
getDomRef,
|
|
515
|
-
nodeType,
|
|
516
|
-
key: 'full-width-label',
|
|
517
|
-
offset: [0, 18],
|
|
518
|
-
absoluteOffset: stickyScrollbar ? { top: -6 } : { top: 0 },
|
|
519
|
-
zIndex: akEditorFloatingPanelZIndex + 1, // Place the context menu slightly above the others
|
|
520
|
-
items: [fullWidthLabel],
|
|
521
|
-
scrollable: true,
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
|
|
525
469
|
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
526
470
|
const nodeType = state.schema.nodes.table;
|
|
527
471
|
const menu = getToolbarMenuConfig(
|
|
@@ -758,7 +702,11 @@ const getColumnSettingItems = (
|
|
|
758
702
|
|
|
759
703
|
const items: Array<FloatingToolbarItem<Command>> = [];
|
|
760
704
|
|
|
705
|
+
const isNested =
|
|
706
|
+
pluginState.tablePos && isTableNested(editorState, pluginState.tablePos);
|
|
707
|
+
|
|
761
708
|
const isTableScalingLockBtnEnabled =
|
|
709
|
+
!isNested &&
|
|
762
710
|
isTableScalingEnabled &&
|
|
763
711
|
getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
|
|
764
712
|
|